converter-z
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

converter

Javascript conmunicates to java with js-to-java need special schemas, we will preprocess data (if you need a number but get a string parameter) then we can use js-to-java to wrap js object to java object.

Build Status npm version

Install

$ npm install converter-z

Usage

Convert primitives data type, like number, string, boolean, and more.

@converter()
method(
  @convert({ type: 'number' }) idnumber, // recommend
  @convert({ id: { type: 'number' } }) idnumber, // deprecated
) {
  ...
}

Convert primtives data type in array

@converter()
method(
  @convert({ type: 'number' }) idsnumber[], // recommend
  @convert({ ids: { type: 'number' } }) idsnumber[], // deprecated
) {
  ...
}

Convert shallow object

@converter()
method(
  @convert({ id: { type: 'number' } }) param{ id: number },
) {
  ...
}

Convert object in array

@converter()
method(
  @convert({ id: { type: 'number' } }) paramArray<{ id: number }>,
) {
  ...
}

Add a new convert type or rewrite convert type

converter.config({
  type: 'increase',
  adaptor: (value, required?: boolean, message?:string) => {
    let nextValue = value
    if (value === '' || value === null || value === undefined) {
      if (required) throw new Error(message)
      nextValue = null
    } else {
      nextValue = +value + 1
    }
    return nextValue
  },
})

Convert deep object

@converter()
method(
  @convert({
    ids: {
      id: { type: 'number' },
    },
  }) param{ ids: { id: number } },
) {
  ...
}

Project progress

  • Converter develop
    • Convert primitives data type, like number, string, boolean, and more
    • Convert primtives data type in array
    • Convert shallow object
    • Convert object in array
    • Add a new convert type or rewrite convert type
    • Convert deep object
    • More

License

MIT

Package Sidebar

Install

npm i converter-z

Weekly Downloads

2

Version

0.2.2

License

MIT

Unpacked Size

13 kB

Total Files

14

Last publish

Collaborators

  • shinken008