0.2.2 • Published 5 years ago

converter-z v0.2.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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' }) id: number, // recommend
  @convert({ id: { type: 'number' } }) id: number, // deprecated
) {
  ...
}

Convert primtives data type in array

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

Convert shallow object

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

Convert object in array

@converter()
method(
  @convert({ id: { type: 'number' } }) param: Array<{ 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

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago