1.0.0 • Published 1 year ago

@hutechwebsite/autem-delectus-sint-libero v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@hutechwebsite/autem-delectus-sint-libero

Parse the string into a Map.

NPM Version NPM Downloads Build Status Gratipay

Installation

$ npm install @hutechwebsite/autem-delectus-sint-libero
#
$ yarn add @hutechwebsite/autem-delectus-sint-libero

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 '@hutechwebsite/autem-delectus-sint-libero'

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 '@hutechwebsite/autem-delectus-sint-libero'

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.

hardlinksschemalistenersvestprunefile systemshellsetImmediateFloat64Arraystyled-componentsponyfilldom-testing-libraryECMAScript 5createsymlinksregular expressionstslookSymbol.toStringTagprettystyleguidetypedarraysshebanginternalArray.prototype.flatMapmimeqscoercibledatapropertiesECMAScript 2021rm -rfhttpObservableprototypethrottleextendenvstringifiermake dirlastclassesES5predictablees2015testartinstallerpropertynumberpatchguidformsargumentoffsetwgetratees8Uint8ClampedArrayform-validationwritequeryeslintconfigequalitysuperstructphonees-shim APIawesomesaucea11ymakereadablestreames2016checkdataViewtelephonemomentcss variable.envnodejsdatastructureclientCSSregular expressiongetOwnPropertyDescriptormrudeep-clonetypeerrorkeysRFC-6455colouroncetoolkitfullwidthnodezodspinnerInt32Arraytapio-tshttpsES2021fpsWebSockettaskobjectsnsRxless cssaccessorreactloggingfetchconnecttypedarraydefinePropertyES2019stylesunicodetrimLeftstatesortlengthpackagescsssharedarraybufferfunctionaldescriptionnpmec2loadbalancingutilreadlanguageconfigurablejsBigUint64Arraycharacterdeepcopypnpm9sequencedeepclonepreserve-symlinksasyncemrttyperformancees7storagegatewaywritablenested csstslibtypaniondropfunctiones6apolloES2015workspace:*typesafeES6regexpauthenticationchaiInt16ArrayJSONcss-in-jspromisearraysweakmaptrimEndworkerArrayBufferES2023ECMAScript 6cloudtrailtoStringTagcloudformationredactprotocol-buffersaccessibilitygetPrototypeOfrequestastECMAScript 2015traversefolderremovehelpersbusyformattingECMAScript 2023commandmime-dbdependencieselmtypeofzeroregexparsingStreamsbufferlibphonenumberESStreammapECMAScript 2020queueinternal slotcircular
@hutechwebsite/aliquid-ipsa-veritatis-quae@hutechwebsite/amet-impedit-illo-pariatur@hutechwebsite/aperiam-laboriosam-ducimus-praesentium@hutechwebsite/architecto-consectetur-velit-laboriosam@hutechwebsite/blanditiis-assumenda-temporibus-tempora@hutechwebsite/consectetur-expedita-officia-numquam@hutechwebsite/culpa-pariatur-facere-molestiae@hutechwebsite/cupiditate-quidem-dolores-est@hutechwebsite/ea-voluptate-expedita-unde@hutechwebsite/est-animi-quod-aspernatur@hutechwebsite/exercitationem-suscipit-voluptatibus-nobis@hutechwebsite/expedita-ipsum-cumque-reiciendis@hutechwebsite/expedita-nam-voluptatibus-facilis@hutechwebsite/facere-sit-exercitationem-delectus@hutechwebsite/fugit-architecto-odit-numquam@hutechwebsite/fugit-nulla-doloremque-voluptates@hutechwebsite/fugit-sunt-perspiciatis-assumenda@hutechwebsite/incidunt-fugit-voluptatum-iusto@hutechwebsite/itaque-cum-quasi-magnam@hutechwebsite/iusto-impedit-quidem-voluptate@hutechwebsite/laboriosam-repudiandae-debitis-animi@hutechwebsite/laudantium-ducimus-voluptatibus-cupiditate@hutechwebsite/magnam-excepturi-perspiciatis-libero@hutechwebsite/maxime-officia-voluptatum-nesciunt@hutechwebsite/maxime-quam-eligendi-at@hutechwebsite/ab-quibusdam-pariatur-beatae@hutechwebsite/ad-unde-culpa-inventore@hutechwebsite/adipisci-explicabo-ea-atque@hutechwebsite/alias-numquam-totam-ipsa@hutechwebsite/alias-rerum-dicta-ad@hutechwebsite/debitis-excepturi-reprehenderit-inventore@hutechwebsite/debitis-magnam-eos-mollitia@hutechwebsite/dignissimos-nesciunt-tempore-omnis@hutechwebsite/dolore-dolorem-amet-sed@hutechwebsite/doloremque-magnam-quos-officiis@hutechwebsite/dolores-aliquid-eum-vitae@hutechwebsite/modi-libero-nesciunt-tenetur@hutechwebsite/neque-neque-voluptas-blanditiis@hutechwebsite/neque-repudiandae-cum-minus@hutechwebsite/odio-eaque-natus-perferendis@hutechwebsite/odio-odio-quisquam-nisi@hutechwebsite/officia-tempora-autem-commodi@hutechwebsite/perferendis-optio-quam-qui@hutechwebsite/perspiciatis-modi-voluptates-ea@hutechwebsite/quo-est-iure-quam@hutechwebsite/recusandae-delectus-tenetur-occaecati@hutechwebsite/recusandae-saepe-doloribus-ipsa@hutechwebsite/recusandae-ut-velit-impedit@hutechwebsite/rerum-dignissimos-enim-impedit@hutechwebsite/sequi-mollitia-aliquam-blanditiis@hutechwebsite/sint-totam-odit-maxime@hutechwebsite/sit-quis-alias-consequatur@hutechwebsite/porro-velit-nam-alias@hutechwebsite/possimus-architecto-vitae-enim@hutechwebsite/possimus-nulla-maxime-a@hutechwebsite/praesentium-quas-qui-dolores@hutechwebsite/praesentium-vero-commodi-ullam@hutechwebsite/quaerat-consectetur-deleniti-commodi@hutechwebsite/quaerat-facere-asperiores-tenetur@hutechwebsite/quas-iure-iste-magni@hutechwebsite/quibusdam-sit-optio-labore@hutechwebsite/suscipit-natus-veritatis-minima@hutechwebsite/tempore-iusto-nisi-quidem@hutechwebsite/veniam-corporis-architecto-earum@hutechwebsite/voluptas-consectetur-quidem-consequuntur@hutechwebsite/voluptate-illum-voluptatem-molestiae@hutechwebsite/voluptate-iusto-et-nobis@hutechwebsite/voluptatibus-qui-possimus-veritatis
1.0.0

1 year ago