{"_id":"@128keaton/ts-serializer","_rev":"2-07c90e4ebc5401e43a09786eb0e4518b","name":"@128keaton/ts-serializer","dist-tags":{"latest":"2.2.3"},"versions":{"2.2.2":{"name":"@128keaton/ts-serializer","version":"2.2.2","repository":{"type":"git","url":"git+https://github.com/128keaton/ts-serializer.git"},"author":{"name":"Daniel Popescu","email":"danielpopescu95@gmail.com"},"contributors":[{"name":"Fellipe Pinheiro","email":"pinheiro.llip@gmail.com"}],"license":"Apache-2.0","keywords":["typescript","serialize","deserialize","library","json","mapping"],"bugs":{"url":"https://github.com/delete/ts-serializer/issues"},"homepage":"https://github.com/delete/ts-serializer#readme","main":"dist/ts-serializer.js","module":"dist/ts-serializer.js","typings":"dist/ts-serializer.d.ts","scripts":{"build":"webpack","test":"jest --verbose --coverage"},"peerDependencies":{},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"devDependencies":{"@types/jest":"^24.0.13","jest":"^24.8.0","prettier":"^1.17.1","ts-jest":"^24.0.2","ts-loader":"^6.0.2","typescript":"^3.4.5","webpack":"^4.33.0","webpack-cli":"^3.3.4"},"jest":{"transform":{"^.+\\.tsx?$":"ts-jest"},"globals":{"ts-jest":{"diagnostics":false}}},"gitHead":"2924d016787a1e351f7103b08475ce2194d4eeb5","description":"<h1 align=\"center\"> TS Serializer</h1>","_id":"@128keaton/ts-serializer@2.2.2","_nodeVersion":"10.14.1","_npmVersion":"6.9.0","dist":{"integrity":"sha512-PMqfmgzQ5Uix8ebWZCiW+oIoh/8b/VEEkHgLBUNwV3OOkTSWg4ot/DIdKc7BWEJCco8bhMkUOipThRruanzV9g==","shasum":"efc1126a18e818d7a56d0108aacc74a0bb5e4b0f","tarball":"https://registry.npmjs.org/@128keaton/ts-serializer/-/ts-serializer-2.2.2.tgz","fileCount":4,"unpackedSize":45302,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdOOXSCRA9TVsSAnZWagAAavoP/0lCHJ8VllftCYeDEO/q\nx+5y0TuEfJmCpZcGg3NjBl6s1qkF1gTW9SPi9V0dHZ0f0VfFjgRSDkXkeRAx\nJCHsq7j12rjy7/bczYcKZQohxB9z7VbhYXrKXt/Xvx4r6LFn/XSiDpg89KkX\niRmoAjNHxysnA+ba36GNHCE/urscLkGv+ESLbcgjvEw94ekRMQkaZWhzJiCR\nuPtcaybc/JrptxcYgG87YyxpH8+VZEmgLJwpTwXO0oNofJi5i5sO62LcYP3R\nAP+WrmcCq062QID+i/iWcd9scZtPDSF+IKUMDJHE0qHCa39V8SDbv1L1eD0/\nKeILff1fOEqx26V6zfoghpByWol/uUMBVhFq+mNqZtQ5C2ohfNOmyxYqNDlk\ni1P56IcBisfBYk8CaCYuGHFuv8MmuApImCPcMy9I8CTI96gH2qVtmaNXFo5u\naXyxWjYGz4Gycx6Kc2kcVWCpJ/f3GnxAWG/GXPbcaXZ6oCSREnLK6neApXvY\nuAyka/3K5bkjex+cO5H5yPpUrtoGzJnSi2oqbJJbFDzFXruK3jmzB0Ph1o8q\nEr6Fk1RwQar7i7dBHNP3HZDJhn+sMRDmtMCPYHICh5FLU2wShvHQ9qubZH71\nassJxFIS/5kduLosU/Cl3d3n5E5M4D3/B7JrXy+fGadAy08WO2Qo10n402Yn\nLoFb\r\n=n/+d\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDGkx8zIfBsjUMLErTzlNy6e13woTJVzCNzRWt+L+UYPAIhAP0sh9XnlVBVPu/jcSAc5DTaV1Oqb4NfpUCGrtluGIXp"}]},"maintainers":[{"name":"128keaton","email":"keaton.burleson@me.com"}],"_npmUser":{"name":"128keaton","email":"keaton.burleson@me.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-serializer_2.2.2_1564009937835_0.32571358729254385"},"_hasShrinkwrap":false},"2.2.3":{"name":"@128keaton/ts-serializer","version":"2.2.3","repository":{"type":"git","url":"git+https://github.com/128keaton/ts-serializer.git"},"author":{"name":"Daniel Popescu","email":"danielpopescu95@gmail.com"},"contributors":[{"name":"Fellipe Pinheiro","email":"pinheiro.llip@gmail.com"}],"license":"Apache-2.0","keywords":["typescript","serialize","deserialize","library","json","mapping"],"bugs":{"url":"https://github.com/delete/ts-serializer/issues"},"homepage":"https://github.com/delete/ts-serializer#readme","main":"dist/ts-serializer.js","module":"dist/ts-serializer.js","typings":"dist/ts-serializer.d.ts","scripts":{"build":"webpack","test":"jest --verbose","test-coverage":"jest --verbose --coverage","publish":"npm publish --access=public"},"peerDependencies":{},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"devDependencies":{"@types/jest":"^24.0.13","jest":"^24.8.0","prettier":"^1.17.1","ts-jest":"^24.0.2","ts-loader":"^6.0.2","typescript":"^3.4.5","webpack":"^4.33.0","webpack-cli":"^3.3.4"},"jest":{"transform":{"^.+\\.tsx?$":"ts-jest"},"globals":{"ts-jest":{"diagnostics":false}}},"gitHead":"2d6b4337e75cce33bfb7959761ac86150df0aa28","description":"<h1 align=\"center\"> TS Serializer</h1>","_id":"@128keaton/ts-serializer@2.2.3","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-W2tQTNuwLaAoIIyp74a82He8G41b6ga8ehhpNMWGrd3BcL7qKRfVR4/fhFQcI+IobSFdpKsAuMY1vykf/s+yFA==","shasum":"3a2925cffc56bc98a2cbe0daac7335042f1167d0","tarball":"https://registry.npmjs.org/@128keaton/ts-serializer/-/ts-serializer-2.2.3.tgz","fileCount":27,"unpackedSize":45139,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdOeomCRA9TVsSAnZWagAAQv8P/R7yE36/b5p30XRkiObL\n2Ig7cyGsn36TU8jzFQBZM+6lsoBXTv8+6CsiDYMkBiEXKfvQL2LWDTCDzBBl\naDk4mQ6SaA+YUCFw9eatC1kuGxQ92W46hMCr3wk1BAdnqAoa4YPbQ+x7JrtO\nz2sOnZC3iV8npQKkMDmkM6S+QvX1Upp8D79bPIZbM0qExfD0f5tH963L9gPX\naDFsBh8J/W5iZnoNEamQ6g7N56Pxb0ry+WlshK61VdAUuiCB8t3rQqHA2PUn\nLk0t2qDdpo0wAnkw3p0Cl3EF1DQghbRpjWA8U09S2Ju7uPgy1Vkekkz/T5l0\nFMDxU6QP6H9lbaVXM7EUePESulOwzeveWbIHX0rxz2ALU2KXkrE44SizcXhL\ns+DEUPoRHLq8fr9b64k7cnF3zAxM3VSCr3yVks/r5FZt6GWeRhtWJns7fI0J\n6WmF6IUyN+GMdjWexpCRHMU1qRiA2nqoszsGjBil4fNpprZ5ooATF4SOR5yu\nSvKADJFiDvbpo3gznLOAkTZGUakAYTwDTXrpa81kSmqS+Bse7AhEktmNVMhk\nhH8o8tYMZT656mqgZqUOru+cz1uIALCQKtNVI4hHFQP3EOCkRajw51fVWiud\n4trmbCuqIJVGu8I/WMyMwfIenHIdTWBkCFkBobBNn3Gq8I+FMCPucpfXXTrq\n//LO\r\n=7CyE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH/gSdqwqE0ExCniyMV/XYyIVjCzgm/DoQlawEfBnzSHAiAEYLDpJ8I4cAdSKgkf0Mf1uDbz5Hxww52a/9LTbczpuA=="}]},"maintainers":[{"name":"128keaton","email":"keaton.burleson@me.com"}],"_npmUser":{"name":"128keaton","email":"keaton.burleson@me.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-serializer_2.2.3_1564076581249_0.3707254762068024"},"_hasShrinkwrap":false}},"time":{"created":"2019-07-24T23:12:17.638Z","2.2.2":"2019-07-24T23:12:17.982Z","modified":"2022-04-04T10:31:10.754Z","2.2.3":"2019-07-25T17:43:01.382Z"},"maintainers":[{"name":"128keaton","email":"keaton.burleson@me.com"}],"description":"<h1 align=\"center\"> TS Serializer</h1>","homepage":"https://github.com/delete/ts-serializer#readme","keywords":["typescript","serialize","deserialize","library","json","mapping"],"repository":{"type":"git","url":"git+https://github.com/128keaton/ts-serializer.git"},"contributors":[{"name":"Fellipe Pinheiro","email":"pinheiro.llip@gmail.com"}],"author":{"name":"Daniel Popescu","email":"danielpopescu95@gmail.com"},"bugs":{"url":"https://github.com/delete/ts-serializer/issues"},"license":"Apache-2.0","readme":"<h1 align=\"center\"> TS Serializer</h1>\r\n\r\n<p align=\"center\">\r\n  <a href=\"https://www.npmjs.com/package/@delete21/ts-serializer\" target=\"_blank\">\r\n    <img src=\"https://img.shields.io/npm/dt/@delete21/ts-serializer.svg\" alt=\"npm\" />\r\n  </a>\r\n  <a href=\"https://github.com/delete/ts-serializer/blob/master/LICENSE\" target=\"_blank\">\r\n    <img src=\"https://img.shields.io/npm/l/@delete21/ts-serializer.svg\" alt=\"license\" />\r\n  </a>\r\n  <a href=\"https://github.com/delete/ts-serializer/stargazers\" target=\"_blank\">\r\n    <img alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/delete/ts-serializer.svg?style=social\" alt=\"stars\">\r\n  </a>\r\n</p>\r\n\r\n<br />\r\n\r\n> **TS Serializer** provides `TypeScript` decorators to help developers with serializing/deserializing TypeScript classes into and from JSON objects.\r\n\r\n\r\n## This project is a fork from [dpopescu's project](https://github.com/dpopescu/ts-serializer)\r\n\r\n### Why?\r\nThe project is not maintained anymore and there are some feature and fixes that me and my team needed:\r\n\r\n- `optional` property option, disscursed here [issue 10](https://github.com/dpopescu/ts-serializer/issues/10) - [commit here](https://github.com/delete/ts-serializer/commit/d5eb8121af08a00635d7445f50507c20a513127d)\r\n- fix to properties with falsy values such as `0` (zero) and `false` that should be valid - [commit here](https://github.com/delete/ts-serializer/commit/926f3c6d945b2ab32fa551c07912d43a469a5702)\r\n\r\n\r\n\r\n## Installation\r\n### Using npm:\r\n`npm install --save @delete21/ts-serializer`\r\n\r\n## Usage\r\n\r\nYou can find a [codesandbox playground here](https://codesandbox.io/s/ts-serializer-playground-gdbid)!\r\n\r\n### TypeScript\r\n#### Deserialization:\r\n```TypeScript \r\nimport {Serialize, SerializeProperty, Serializable} from '@delete21/ts-serializer';\r\n\r\n@Serialize({})\r\nclass MyClass extends Serializable {\r\n    @SerializeProperty({\r\n        map: 'username'\r\n    })\r\n    public name:string;\r\n}\r\n\r\nlet instance:MyClass = new MyClass();\r\n\r\nconsole.log(instance.name); // Prints `undefined`\r\n\r\ninstance.deserialize({\r\n    username: 'Some Value'\r\n});\r\n\r\nconsole.log(instance.name); // Prints 'Some Value'\r\n```\r\n---\r\n#### Serialization:\r\n```TypeScript\r\nimport {Serialize, SerializeProperty, Serializable} from '@delete21/ts-serializer';\r\n\r\n@Serialize({})\r\nclass MyClass extends Serializable {\r\n    @SerializeProperty({\r\n        map: 'username'\r\n    })\r\n    public name:string;\r\n}\r\n\r\nlet instance:MyClass = new MyClass();\r\ninstance.name = 'Some Value';\r\n\r\nconsole.log(instance.serialize()); // Prints {username:'Some Value'}\r\n```\r\n### JavaScript\r\n> **Note:** Although the library was designed to be used as a decorator in TypeScript, it doesn't matter that it can't be used in plain old JavaScript. The syntax can be a little messy but the result is the same.\r\n\r\n#### Deserialization:\r\n```JavaScript\r\nvar Serialize = TSerializer.Serialize;\r\nvar SerializeProperty = TSerializer.SerializeProperty;\r\n\r\nfunction MyClass(){\r\n    this.name;\r\n}\r\n\r\nSerialize({})(MyClass);\r\nSerializeProperty({\r\n   map: 'username'\r\n})(MyClass.prototype, 'name');\r\n\r\nvar instance = new MyClass();\r\n\r\nconsole.log(instance.name); // Prints `undefined`\r\n\r\ninstance.deserialize({\r\n    username: 'Some Value'\r\n});\r\n\r\nconsole.log(instance.name); // Prints 'Some Value'\r\n```\r\n---\r\n#### Serialization:\r\n```JavaScript\r\nvar Serialize = TSerializer.Serialize;\r\nvar SerializeProperty = TSerializer.SerializeProperty;\r\n\r\nfunction MyClass(){\r\n    this.name = 'Some Value';\r\n}\r\n\r\nSerialize({})(MyClass);\r\nSerializeProperty({\r\n   map: 'username'\r\n})(MyClass.prototype, 'name');\r\n\r\nvar instance = new MyClass();\r\n\r\nconsole.log(instance.serialize()); // Prints {username:'Some Value'}\r\n```\r\n## Library Options\r\nThe library allows you to pass different serialization/deserialization options both on class level and on property level.  \r\n### Class Options\r\n#### root\r\nWhen you want to deserialize just a child object from the JSON you can use the `root` option.\r\n```TypeScript\r\n@Serialize({\r\n    root: 'childObject'\r\n})\r\nclass MyClass extends Serializable {\r\n    @SerializeProperty({})\r\n    public name:string;\r\n}\r\n\r\nlet instance:MyClass = new MyClass();\r\ninstance.deserialize({\r\n    childObject: {\r\n        name: 'Some Value'\r\n    }\r\n});\r\n\r\nconsole.log(instance.name); // Prints 'Some Value'\r\n```\r\n### Property Options\r\n#### root\r\nThe `root` option can also be used on a property.\r\n\r\n> **Note:** If `root` is already specified at class level the value is inherited to all class properties. If you want to override this, you can use hte `.` value. In this case, the property will be mapped up one level.\r\n\r\n```TypeScript\r\n@Serialize({})\r\nclass MyClass extends Serializable {\r\n    @SerializeProperty({\r\n        root: 'childObject'\r\n    })\r\n    public name:string;\r\n}\r\n\r\nlet instance:MyClass = new MyClass();\r\ninstance.deserialize({\r\n    childObject: {\r\n        name: 'Some Value'\r\n    }\r\n});\r\n\r\nconsole.log(instance.name); // Prints 'Some Value'\r\n```\r\n---\r\n#### map\r\nWhen the property name in the JSON doesn't match with your class properties, the `map` option can be used. This option maps a property from the JSON with a different property from your class.\r\n```TypeScript\r\n@Serialize({})\r\nclass MyClass extends Serializable {\r\n    @SerializeProperty({\r\n        map: 'username'\r\n    })\r\n    public name:string;\r\n}\r\n\r\nlet instance:MyClass = new MyClass();\r\ninstance.deserialize({\r\n    username: 'Some Value'\r\n});\r\n\r\nconsole.log(instance.name); // Prints 'Some Value'\r\n```\r\n---\r\n#### list\r\nThe `list` option can be used when the JSON property value is a list of items. \r\n```TypeScript\r\n@Serialize({})\r\nclass MyClass extends Serializable {\r\n    @SerializeProperty({\r\n        list: true\r\n    })\r\n    public items:string[];\r\n}\r\n\r\nlet instance:MyClass = new MyClass();\r\ninstance.deserialize({\r\n    items: ['a', 'b', 'c']\r\n});\r\n\r\nconsole.log(instance.items); // Prints ['a', 'b', 'c']\r\n```\r\n---\r\n#### type\r\nWhen you want to use non-primitive types for deserialization use the `type` option.\r\n\r\n> **Note:** The `type` object should also be a `Serializable` object.\r\n\r\n```TypeScript\r\n@Serialize({})\r\nclass User extends Serializable {\r\n    @SerializeProperty({})\r\n    public firstName:string;\r\n    @SerializeProperty({})\r\n    public lastName:string;\r\n} \r\n\r\n@Serialize({})\r\nclass Profile extends Serializable {\r\n    @SerializeProperty({\r\n        type: User\r\n    })\r\n    public user:User;\r\n}\r\n\r\nlet instance:Profile = new Profile();\r\ninstance.deserialize({\r\n    user: {\r\n        firstName: 'John',\r\n        lastName: 'Doe'\r\n    }\r\n});\r\n\r\nconsole.log(instance.user.firstName); // Prints 'John'\r\nconsole.log(instance.user.lastName); // Prints 'Doe'\r\n```\r\n\r\n#### optional\r\nThe `optional` option can be used when the property or the value may not exist. \r\n```TypeScript\r\n@Serialize({})\r\nclass User extends Serializable {\r\n    @SerializeProperty({})\r\n    public name:string;\r\n    @SerializeProperty({\r\n        optional: true\r\n    })\r\n    public age:number;\r\n} \r\n\r\n@Serialize({})\r\nclass Profile extends Serializable {\r\n    @SerializeProperty({\r\n        type: User\r\n    })\r\n    public user:User;\r\n}\r\n\r\nlet instance:Profile = new Profile();\r\ninstance.deserialize({\r\n    user: {\r\n        firstName: 'John',\r\n    }\r\n});\r\n\r\nconsole.log(instance.user.firstName); // Prints 'John'\r\nconsole.log(instance.user.age); // Prints 'null'\r\n```\r\n\r\n# Contribute\r\n\r\nYou can help improving this project sending PRs and helping with issues.  \r\nAlso you can ping me at [Twitter](http://twitter.com/pinheirofellipe)","readmeFilename":"README.md"}