5.8.132 • Published 2 years ago

@diotoborg/sed-minus-itaque v5.8.132

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@diotoborg/sed-minus-itaque

Parse the string into a Map.

NPM Version NPM Downloads Build Status Gratipay

Installation

$ npm install @diotoborg/sed-minus-itaque
#
$ yarn add @diotoborg/sed-minus-itaque

Features

  • parse string into Map
  • format data
  • filter and verify data.
  • verify signature.

API

toValue (type: 'string' | 'number' | 'date' | 'map' = 'string'): (value: any) => any

Convert specified type value.

  • type - target type
  • value - value of need convert

formatData (formats?: ParseData.format | ParseData.format[], customize?: Record<string, Function>): (value: any) => any

Format Data.

  • formats - formatting options
  • customize - map of custom function
  • value - value of need format

parseData (options: ParseData.options, customize?: Record<string, Function>): (data: string) => Record<string, any>

Parse the string to the specified result.

  • options - parsing options
  • customize - map of custom function
  • data - data of need parse

parseBody (options: ParseData.parse[], customize?: Record<string, Function>): (msgbody: Record<string, any>) => Record<string, any>

Parse the msbody to the specified result.

  • options - parsing options
  • customize - map of custom function
  • msbody - msbody of need parse

filterData (options: FilterData.options[], customize?: Record<string, Function>): (data: Record<string, any>) => Record<string, any>

Filter and verify data.

  • options - filter options
  • customize - map of custom function
  • data - data of need filter

validSign (options: string, sign: string = 'sign'): (data: Record<string, any>) => boolean

Verify signature.

  • options - style of signature
  • sign - feild of signature
  • data - data of submit

Usages

Example: Parse string

import { parseData } from '@diotoborg/sed-minus-itaque'

const customize = {
  add: (a, b) => a + b
}

const options = {
  separator: /\;/,
  collection: [
    {
      key: 'date',
      type: 'string',
      format: [
        {
          type: 'string',
          regexp: /^(\d{4})(\d{2})(\d{2})$/,
          substr: '$1-$2-$3'
        },
        {
          type: 'date'
        }
      ]
    },
    {
      key: 'amount',
      type: 'number'
    },
    {
      key: 'user',
      type: 'map'
    },
    {
      key: 'username',
      result: {
        defaultValue: '$__user'
      },
      format: {
        type: 'map',
        maps: 'username'
      }
    },
    {
      key: 'group',
      result: {
        defaultValue: '$__user'
      },
      format: {
        type: 'map',
        maps: 'group.name'
      }
    },
    {
      key: 'level',
      result: {
        defaultValue: '$__user'
      },
      format: {
        type: 'map',
        maps: 'group.level'
      }
    },
    {
      key: 'money1',
      result: {
        defaultValue: '$__amount',
        formula: {
          exec: (a, b) => a + b,
          opts: [ '$__amount', '$__level' ]
        }
      }
    },
    {
      key: 'money2',
      result: {
        defaultValue: '$__amount',
        formula: {
          exec: 'add',
          opts: [ '$__amount', '$__level' ]
        }
      }
    }
  ],
  omits: [ 'user' ]
}

const data = '20201027;39554;{username:\'thondery\',group:{name:\'管理员\',level:9999}}'

parseData(options, customize)(data)
// { 
//   date: 2020-10-27T00:00:00.000Z,
//   amount: 39554,
//   username: 'thondery',
//   group: '管理员',
//   level: 9999,
//   money1: 49553,
//   money2: 49553 
// }

Example: Filter and verify data

import { filterData, validSign } from '@diotoborg/sed-minus-itaque'

const customize = {
  isPassword: value => /^(?=.*[A-Za-z])[A-Za-z0-9$@$!%*#?&]/.test(value)
}

const options = [
  {
    key: 'username',
    type: 'string',
    rules: [
      { required: true, message: '用户名不能为空' },
      { min: 4, max: 12, message: '用户名长度不能小于4或大于12(字符)' },
      { pattern: '^[a-zA-Z]{1}[a-zA-Z0-9\_\-]', message: '用户名格式错误' }
    ]
  },
  {
    key: 'password',
    type: 'string',
    rules: [
      { required: true, message: '密码不能为空' },
      { min: 6, max: 15, message: '密码长度不能小于6或大于15(字符)' },
      { validator: 'isPassword', message: '密码格式错误' }
    ]
  },
  {
    key: 'items',
    type: 'string[]',
    defaultValue: []
  },
  {
    key: 'sign',
    type: 'string',
    md5: '${password}${username}'
  }
]

const data = { username: 'thondery', password: 'a123456', items: '1001,1002,1003' }

try {
  let result = filterData(options, customize)(data)
  // {
  //   username: 'thondery', 
  //   password: 'a123456', 
  //   items: ['1001', '1002', '1003'],
  //   sign: '61a0375131b33b72b56e4e244d0b2f29'
  // }
} catch (error) {
  console.error(error.message)
}

validSign('${password}${username}', 'sign')({ username: 'thondery', password: 'a123456', sign: '61a0375131b33b72b56e4e244d0b2f29' })
// true or false

License

this repo is released under the MIT License.

airbnbnodejsArray.prototype.flatMapes8Int8Arraylistenerscircularautoscalingstringifydescriptorprefix-0emrvisualargvpropertiesstatelessWeakMapconcatString.prototype.matchAllnodemkdirpastRxstyleguidechromiumECMAScript 2021jshintaccessibilityrouteanimationhasOwnparsingyupnopecloudsearchES2018hashECMAScript 2017hasOwnPropertyenvcallbackcallbindnativeopenmkdirmimetypesiteratorbreaknpmsearchsuperagentjapaneseextensionimportexportprototyperequestclientworkflowflattenES7loadbalancinges6react-hooksperformantserializationBigInt64ArraypositivecloudtrailECMAScript 7datastructureInt16Arrayxtermwebsiteguidwritebindfast-copyslotdependency managersidecall-bindargparsehelpersutilunicodereact-testing-libraryJSONbrowserslistwalkomitobjtddl10nRegExp#flagsminimalrm -friconvaccessorrdstc39reactproxypackage managerinternal slottypanionRxJStermmomentebsroute53dotenvspringes2015structuredClonebddassertionkarmafullArray.prototype.filterfastcopyreadablecopyserializerieansiES2020SetentriespolyfillautoprefixerurlssyntaxerroreditorrequirecoercibledefaulthooksjasminefetchponyfillsymlinksprettyeventDispatcherPushwarningObject.keysjsdomstylesregexcodesinspectdebugcontainsstdlibwhichvalidateredirectlimitedbannertyped arrayscheme-validationfast-deep-cloneprotocol-buffersconvertchildperformanceprunereadglobalsES8keytypescriptfigletlookdeep-clonetrimRighttrimLeftrandomsetImmediateratequoterfc4122webprivateespreedayjsjestendersharedarraybufferes-shimsarktypetasksomeequalitytypemetadataregular expressionasyncFloat32Arrayes2018multi-packagecolumnurlbundlinges5RFC-6455bluebirddatacolorsflagmovewaapiindicatortapeURLWebSocketsECMAScript 2019extendthreemimecompilerUint8ClampedArrayCSSStyleDeclarationESnextfilterpnpm9channelexemkdirsdescriptionformatSymbol.toStringTagtexterror__proto__StreamcheckspecsettingsbrowserlistcolouroptionwritableexpressFunction.prototype.namejsondefinePropertysqsreadablestreampromiseawaitttygdprassertsmatchesECMAScript 3utilityincludeswafStreamsargumentsterminalhelperstreamsWeakSetInt32ArraynametostringtagfolderuninstallMapcloneObject.entrieskinesiswaitbeanstalkparsefunctioncommandeslintspinnersweakmapvaluefind-upgetHyBiformcolorawsArray.prototype.containszeroES2016resolveinvariantendpointdefineECMAScript 6configurablebundlerstringifierdom-testing-libraryshrinkwrappatchiamreducerapidprivate datatypesafetoobject[[Prototype]]hardlinksES2023cmdrangeerrorsesphoneuuidTypeBoxeslintconfigtrimlastfastifyxdg-opensyntaxpreserve-symlinksbufferhttppipehttpscorefullwidthgetPrototypeOfconsoleparentstypedarraysdeleterm -rfTypeScriptyamlvalidationowngesturesimporttrimStartspawnworkerYAMLlanguagehas-ownopensgraphqlelbextrajspromisescliimmerfastutilitiesschemefunctionalviewsafeajaxnamesclass-validatorvpcs3argsECMAScript 2022jsdiffArrayBufferlogginglocationtoolsjsxtestingmodulejoipopmotionArray.prototype.findLastIndexes7asciiES2015stylingObject.definePropertydebuggervariableschromesequencepropertyformscode pointsoncetimehasObservablelogmochai18ntrimEndObject.fromEntriesformattingmruECMAScript 2023directoryschemaelasticacheec2idpostcssarrayscharsetexpressionoptimistcommand-lineFloat64ArraywrapRegExp.prototype.flagsstylesimpledbES2022call-boundbuffers.envSymbolpropsharedflatcharacterinstallerequalemojilazytypeofjsonpathratelimitkoreanjQueryglacierforEachlrusameValueZeroimmutableestreeparserObject.assignArray.prototype.flatprogresscollectionfastcloneconcurrencyenvironmentsfindLastIndexrmdiropenerweaksetvaluesinstalltoStringTagredux-toolkittoolkitescapewordwrapnumber$.extendtelephonecachefstesterloggerdirpersistentjavascriptdataviewnegativeObjectbrowsertakeObject.getPrototypeOfthrottleio-tsparentmerge
3.2.24

2 years ago

3.2.23

2 years ago

3.2.26

2 years ago

3.2.25

2 years ago

3.2.28

2 years ago

3.2.27

2 years ago

3.2.29

2 years ago

5.5.110

2 years ago

5.5.111

2 years ago

5.8.131

2 years ago

3.2.20

2 years ago

5.8.132

2 years ago

3.2.22

2 years ago

3.2.21

2 years ago

5.5.107

2 years ago

4.3.53

2 years ago

5.5.108

2 years ago

4.3.52

2 years ago

5.5.105

2 years ago

4.3.51

2 years ago

5.5.106

2 years ago

4.3.50

2 years ago

5.5.103

2 years ago

5.5.104

2 years ago

4.3.55

2 years ago

4.3.54

2 years ago

5.4.78

2 years ago

5.4.79

2 years ago

5.4.76

2 years ago

5.4.77

2 years ago

5.5.109

2 years ago

5.8.128

2 years ago

5.8.129

2 years ago

5.8.126

2 years ago

5.8.127

2 years ago

3.2.31

2 years ago

3.2.30

2 years ago

4.3.42

2 years ago

4.3.41

2 years ago

4.3.40

2 years ago

5.8.130

2 years ago

4.3.46

2 years ago

4.3.45

2 years ago

4.3.44

2 years ago

4.3.43

2 years ago

4.3.49

2 years ago

4.3.48

2 years ago

4.3.47

2 years ago

5.7.120

2 years ago

5.7.119

2 years ago

5.3.72

2 years ago

5.3.71

2 years ago

5.3.70

2 years ago

3.2.15

2 years ago

3.2.14

2 years ago

3.2.17

2 years ago

3.2.16

2 years ago

3.2.19

2 years ago

3.2.18

2 years ago

5.3.76

2 years ago

5.3.75

2 years ago

5.3.74

2 years ago

5.3.73

2 years ago

5.3.61

2 years ago

5.3.60

2 years ago

3.1.14

2 years ago

3.1.13

2 years ago

5.3.69

2 years ago

5.3.68

2 years ago

5.3.67

2 years ago

5.3.66

2 years ago

5.3.65

2 years ago

5.3.64

2 years ago

5.3.63

2 years ago

5.3.62

2 years ago

5.6.119

2 years ago

5.4.102

2 years ago

5.4.103

2 years ago

5.6.111

2 years ago

5.6.112

2 years ago

5.6.113

2 years ago

5.6.114

2 years ago

5.6.115

2 years ago

5.6.116

2 years ago

5.6.117

2 years ago

5.6.118

2 years ago

4.2.31

2 years ago

4.2.32

2 years ago

4.2.33

2 years ago

4.2.34

2 years ago

5.3.59

2 years ago

5.7.123

2 years ago

5.3.58

2 years ago

4.2.39

2 years ago

5.7.124

2 years ago

5.3.57

2 years ago

5.7.121

2 years ago

5.3.56

2 years ago

5.7.122

2 years ago

5.3.55

2 years ago

4.2.35

2 years ago

4.2.36

2 years ago

5.7.125

2 years ago

4.2.37

2 years ago

5.7.126

2 years ago

4.2.38

2 years ago

5.4.94

2 years ago

5.4.95

2 years ago

5.4.92

2 years ago

5.4.93

2 years ago

5.4.90

2 years ago

5.4.91

2 years ago

4.3.39

2 years ago

5.4.100

2 years ago

5.4.101

2 years ago

5.4.98

2 years ago

5.4.99

2 years ago

5.4.96

2 years ago

5.4.97

2 years ago

5.4.83

2 years ago

5.4.84

2 years ago

5.4.81

2 years ago

5.4.82

2 years ago

5.4.80

2 years ago

5.4.89

2 years ago

5.4.87

2 years ago

5.4.88

2 years ago

5.4.85

2 years ago

5.4.86

2 years ago

3.1.12

2 years ago

3.1.11

2 years ago

3.1.10

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.1.7

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago