1.1.2 • Published 4 years ago

json-proxy-mapper v1.1.2

Weekly downloads
80
License
Apache-2.0
Repository
github
Last release
4 years ago

npm version

JSON Proxy mapper

JSON Proxy mapper provides simple wrapped proxy for json.
It wraps obfuscated object and provides named object using ES6 Proxy.

Example

Simple

parts from simple-mapping.test.ts

interface TestObj { // <-- type supports for typescript!

    token: string

}

let testMapping = {

    'token': 't'

}

let wrapped = new WrappedObject<TestObj>({ t: '178231452312' }, new ObjectMapper(testMapping));

console.log(wrapped.named.token === '178231452312'); // true

wrapped.named.token = '172849081972';
console.log(wrapped.original.t === '172849081972'); // true

Nested

parts from nested-mapping.test.ts

interface NestedObj {

    text: string

}

interface TestObj {

    obj: NestedObj

}

let testMapping = {

    'obj': 'o'

}

let nestedMapping = {

    'text': 't'

}

const ConvertMap = {

    'obj': new Converter.Object(nestedMapping)

}

let wrapped = new WrappedObject<TestObj>({ o: { t: '5678' } }, new ObjectMapper(testMapping, ConvertMap));

console.log(wrapped.named.obj.text === '5678'); //true

wrapped.original.o.t = '1234'
console.log(wrapped.named.obj.text === '1234'); //true

wrapped.named.obj.text = '4321'
console.log(wrapped.original.o.t === '4321'); //true

wrapped.named.obj = { text: '1111' }
console.log(wrapped.original.o.t === '1111'); //true

wrapped.original.o = { t: '2222' }
console.log(wrapped.named.obj.text === '2222'); //true

Serialize

parts from serialize.test.ts

interface NestedObj {

    text: string

}

interface TestObj {

    obj: NestedObj

}

let testMapping = {

    'obj': 'o'

}

let nestedMapping = {

    'text': 't'

}

const convertMap = {

    'obj': new Converter.Object(nestedMapping)

}

let deserialized = { obj: { text: 'asdf' } };
console.log(Serializer.serialize(deserialized, new ObjectMapper(testMapping, convertMap))); //{ o: { t: 'asdf' } }

License

json-object-mapper is following Apache 2.0 License.

1.1.2

4 years ago

1.1.1

4 years ago

1.2.0

4 years ago

1.0.2

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago