{"_id":"@bandyer/ts-transformer-type-structure","_rev":"11-fce21a58cb84227283c28553f785df48","time":{"0.1.0":"2020-04-24T16:41:17.286Z","created":"2020-04-24T16:42:26.680Z","1.0.0":"2020-04-24T16:42:27.063Z","modified":"2024-02-26T15:06:10.253Z"},"name":"@bandyer/ts-transformer-type-structure","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bandyer/ts-transformer-type-structure","version":"1.0.0","description":"A TypeScript custom transformer which enables to obtain structure of a given type.","scripts":{"prepare":"tsc","prepublishOnly":"npm test","test":"node test/compile && mocha test"},"repository":{"type":"git","url":"git+https://github.com/bandyer/ts-transformer-type-structure.git"},"keywords":["TypeScript"],"author":{"name":"Bandyer"},"license":"MIT","bugs":{"url":"https://github.com/bandyer/ts-transformer-type-structure/issues"},"homepage":"https://github.com/bandyer/ts-transformer-type-structure#readme","devDependencies":{"@types/mocha":"^5.2.7","@types/node":"^12.12.12","mocha":"^7.1.1","typescript":"^3.8.3"},"peerDependencies":{"typescript":">=2.4.1"},"gitHead":"b39bb42c54799873d667fdf89db4acce90c50567","_id":"@bandyer/ts-transformer-type-structure@1.0.0","_nodeVersion":"13.13.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-xv0GK2OKvMSQjVxxI3cbsiz1TPlh4728JSbddGb+O7aRQgM/KEVY25dgEqNkxxBxBQj4I8BKv5fKb+iwrcRhHA==","shasum":"45b07ee100fbb1ae8cbec5d3f4fabad46717a5a2","tarball":"https://registry.npmjs.org/@bandyer/ts-transformer-type-structure/-/ts-transformer-type-structure-1.0.0.tgz","fileCount":11,"unpackedSize":23603,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeoxbzCRA9TVsSAnZWagAAhWUQAIPR+Z4nCFaaabOxPA6k\n/z7evreNFQNcHPLogVvdr3FsZDTYUznvp6de6zI/3rl/ZttrTkZaTPf8Morx\nFCwcGCIvh6+I2EO01KTiDRma009sYI09O5Ho5LH98An/Iv1/eBH7Bnp6Ev9M\nR4keqpWx0w+1iQ/o045Wun1MzfO31mYbdp+80eUc1jA6Zxo+v873VCnqkzFE\nNntWd5ql98VsS4XtkJB+gdRrzHBHydZzv7khoGC8m6WqoWv3V2WhgAudrzrl\nCxRoNXkbQvWt/z8XvPkuP8EZUeObdzHpwUfz+zZQXvtwU5FMXcw4alREMzWG\nAicXNCnhrrRrFiKB29yD/ywr1IHgZmii1+iJYtzbahhwyodcNGxT4x3ux0K0\n6NGu22DsWP8pkJTSRL54Kl6jRshMwYR/VnVgCQT+UXn8posJlHCAh3zbxaiX\npnQFUz922r2YhchhvbLb6IqkzZ+3j46GZuTqqjYFn3zZ1L6CVxK7GO7Vb/WV\nQ4VEriLa+CnQnL0jFzBtgzhj6Ip19kePKiXU3TT9eda5vosLJC4ohD5gUh0g\nkV/rS4388qoBh1cvoI/McBbVcQHtsz4Dxz7MC4+04t3dZ0U+Cz2CAo07eGNS\nWZoxUNvqyPhDulx8jEHZXE1b/wtAbEG4tz+0QKgSCRYjIFMR8e6eb37xccCV\n0eJ1\r\n=yq/T\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFrannaB4gnLpsNcNiVg1aQkhxodt3iOaMyYBSOzGymQAiEA+2LNBRkDU0d6BVkLs8OmoFPVvEPERA8tQ3Z7BX7Prbk="}]},"maintainers":[{"name":"dalda95","email":"debenedetto95@gmail.com"},{"name":"kristiyan_bandyer","email":"kristiyan.petrov@bandyer.com"},{"name":"techbandyer","email":"tech@bandyer.com"},{"name":"simomazzoni","email":"simone.mazzoni13@gmail.com"}],"_npmUser":{"name":"kristiyan_bandyer","email":"kristiyan.petrov@bandyer.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-transformer-type-structure_1.0.0_1587746546901_0.7265135981537798"},"_hasShrinkwrap":false,"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"maintainers":[{"email":"alessandro.limardo@kaleyra.com","name":"alessandro.limardo"},{"email":"federico.marin@bandyer.com","name":"fede987"},{"email":"kristiyan.petrov@bandyer.com","name":"kristiyan_bandyer"},{"email":"marco.brescianini@kaleyra.com","name":"marcobrescianini"},{"email":"simone.mazzoni13@gmail.com","name":"simomazzoni"},{"email":"tech@bandyer.com","name":"techbandyer"}],"description":"A TypeScript custom transformer which enables to obtain structure of a given type.","homepage":"https://github.com/bandyer/ts-transformer-type-structure#readme","keywords":["TypeScript"],"repository":{"type":"git","url":"git+https://github.com/bandyer/ts-transformer-type-structure.git"},"author":{"name":"Bandyer"},"bugs":{"url":"https://github.com/bandyer/ts-transformer-type-structure/issues"},"license":"MIT","readme":"# ts-transformer-keys\nA TypeScript custom transformer which enables to obtain keys of given type.\n\n[![Build Status][travis-image]][travis-url]\n[![NPM version][npm-image]][npm-url]\n[![Downloads](https://img.shields.io/npm/dm/ts-transformer-type-structure.svg)](https://www.npmjs.com/package/ts-transformer-type-structure)\n\n# Requirement\nTypeScript >= 2.4.1\n\n# How to use this package\n\nThis package exports 2 functions.\nOne is `keys` which is used in TypeScript codes to obtain keys of given type, while the other is a TypeScript custom transformer which is used to compile the `keys` function correctly.\n\n## How to use `keys`\n\n```ts\nimport { keys } from 'ts-transformer-type-structure';\n\ninterface Props {\n  id: string;\n  name: string;\n  age: number;\n}\nconst keysOfProps = keys<Props>();\n\nconsole.log(keysOfProps); // ['id', 'name', 'age']\n```\n\n## How to use `funs`\n```ts\nimport { funs } from 'ts-transformer-type-structure';\n\ninterface Props {\n  id(): string;\n}\nconst funsOfProps = funs<Props>();\n\nconsole.log(funsOfProps); // [{ name: \"id\", args: [], returnType: { name: \"string\", kind: 143 }, isOptional: false }]\n```\n\n\n## How to use the custom transformer\n\nUnfortunately, TypeScript itself does not currently provide any easy way to use custom transformers (See https://github.com/Microsoft/TypeScript/issues/14419).\nThe followings are the example usage of the custom transformer.\n\n### webpack (with ts-loader or awesome-typescript-loader)\n\nSee [examples/webpack](examples/webpack) for detail.\n\n```js\n// webpack.config.js\nconst keysTransformer = require('ts-transformer-type-structure/transformer').default;\n\nmodule.exports = {\n  // ...\n  module: {\n    rules: [\n      {\n        test: /\\.ts$/,\n        loader: 'ts-loader', // or 'awesome-typescript-loader'\n        options: {\n          // make sure not to set `transpileOnly: true` here, otherwise it will not work\n          getCustomTransformers: program => ({\n              before: [\n                  keysTransformer(program)\n              ]\n          })\n        }\n      }\n    ]\n  }\n};\n\n```\n\n### Rollup (with rollup-plugin-typescript2)\n\nSee [examples/rollup](examples/rollup) for detail.\n\n```js\n// rollup.config.js\nimport resolve from 'rollup-plugin-node-resolve';\nimport typescript from 'rollup-plugin-typescript2';\nimport keysTransformer from 'ts-transformer-keys/transformer';\n\nexport default {\n  // ...\n  plugins: [\n    resolve(),\n    typescript({ transformers: [service => ({\n      before: [ keysTransformer(service.getProgram()) ],\n      after: []\n    })] })\n  ]\n};\n```\n\n### ttypescript\n\nSee [examples/ttypescript](examples/ttypescript) for detail.\nSee [ttypescript's README](https://github.com/cevek/ttypescript/blob/master/README.md) for how to use this with module bundlers such as webpack or Rollup.\n\n```json\n// tsconfig.json\n{\n  \"compilerOptions\": {\n    // ...\n    \"plugins\": [\n      { \"transform\": \"ts-transformer-type-structure/transformer\" }\n    ]\n  },\n  // ...\n}\n```\n\n### TypeScript API\n\nSee [test](test) for detail.\nYou can try it with `$ npm test`.\n\n```js\nconst ts = require('typescript');\nconst keysTransformer = require('ts-transformer-type-structure/transformer').default;\n\nconst program = ts.createProgram([/* your files to compile */], {\n  strict: true,\n  noEmitOnError: true,\n  target: ts.ScriptTarget.ES5\n});\n\nconst transformers = {\n  before: [keysTransformer(program)],\n  after: []\n};\nconst { emitSkipped, diagnostics } = program.emit(undefined, undefined, undefined, false, transformers);\n\nif (emitSkipped) {\n  throw new Error(diagnostics.map(diagnostic => diagnostic.messageText).join('\\n'));\n}\n```\n\nAs a result, the TypeScript code shown [here](#how-to-use-keys) is compiled into the following JavaScript.\n\n```js\n\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ts_transformer_keys_1 = require(\"ts-transformer-type-structure\");\nvar keysOfProps = [\"id\", \"name\", \"age\"];\nconsole.log(keysOfProps); // ['id', 'name', 'age']\n```\n\n# Note\n\n* The `keys` function can only be used as a call expression. Writing something like `keys.toString()` results in a runtime error.\n* `keys` does not work with a dynamic type parameter, i.e., `keys<T>()` in the following code is converted to an empty array(`[]`).\n\n```ts\nclass MyClass<T extends object> {\n  keys() {\n    return keys<T>();\n  }\n}\n```\n\n# Credits\nInspired by [https://github.com/kimamula/ts-transformer-keys](https://github.com/kimamula/ts-transformer-keys)\n\n# License\n\nMIT\n\n[travis-image]:https://travis-ci.org/bandyer/ts-transformer-type-structure.svg?branch=master\n[travis-url]:https://travis-ci.org/bandyer/ts-transformer-type-structure\n[npm-image]:https://img.shields.io/npm/v/ts-transformer-type-structure.svg?style=flat\n[npm-url]:https://npmjs.org/package/ts-transformer-type-structure\n","readmeFilename":"README.md"}