Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-transformer-keys

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-transformer-keys - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

10

package.json
{
"name": "ts-transformer-keys",
"version": "0.3.1",
"version": "0.3.2",
"description": "Check equality of objects based on their contextual type in TypeScript",

@@ -29,6 +29,6 @@ "main": "index.js",

"devDependencies": {
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.13",
"mocha": "^3.2.0",
"typescript": "^2.4.1"
"@types/mocha": "^5.2.3",
"@types/node": "^10.3.5",
"mocha": "^5.2.0",
"typescript": "^2.9.2"
},

@@ -35,0 +35,0 @@ "peerDependencies": {

@@ -33,6 +33,79 @@ # ts-transformer-keys

Unfortunately, the only way currently available to use custom transformers is to use them with TypeScript compiler API (See https://github.com/Microsoft/TypeScript/issues/14419 for detail).
Something like the following works.
Unfortunately, TypeScript itself does not currently provide any easy way to use custom transformers (See https://github.com/Microsoft/TypeScript/issues/14419).
The followings are the example usage of the custom transformer.
### webpack (with awesome-typescript-loader)
See [examples/webpack](ts-transformer-keys/tree/master/examples/webpack) for detail.
```js
// webpack.config.js
const keysTransformer = require('ts-transformer-keys/transformer').default;
module.exports = {
// ...
module: {
rules: [
{
test: /\.ts$/,
loader: 'awesome-typescript-loader',
options: {
getCustomTransformers: program => ({
before: [
keysTransformer(program)
]
})
}
}
]
}
};
```
## Rollup (with rollup-plugin-typescript2)
See [examples/rollup](ts-transformer-keys/tree/master/examples/rollup) for detail.
```js
// rollup.config.js
import typescript from 'rollup-plugin-typescript2';
import keysTransformer from 'ts-transformer-keys/transformer';
export default {
// ...
plugins: [
typescript({ transformers: [service => ({
before: [ keysTransformer(service.getProgram()) ],
after: []
})] })
]
};
```
## ttypescript
See [examples/ttypescript](ts-transformer-keys/tree/master/examples/ttypescript) for detail.
See [ttypescript's README](https://github.com/cevek/ttypescript/blob/master/README.md) for how to use this with module bundlers such as webpack of Rollup.
```json
// tsconfig.json
{
"compilerOptions": {
// ...
"plugins": [
{ "transform": "ts-transformer-keys/transformer" }
]
},
// ...
}
```
## TypeScript API
See [test](ts-transformer-keys/tree/master/test) for detail.
You can try it with `$ npm test`.
```js
const ts = require('typescript');

@@ -58,3 +131,3 @@ const keysTransformer = require('ts-transformer-keys/transformer').default;

As a result, the TypeScript code shown above is compiled into the following JavaScript.
As a result, the TypeScript code shown [here](#how-to-use-this-package) is compiled into the following JavaScript.

@@ -61,0 +134,0 @@ ```js

@@ -36,4 +36,4 @@ "use strict";

&& (path.join(declaration.getSourceFile().fileName) === indexTs)
&& !!declaration.name
&& (declaration.name.getText() === 'keys');
&& !!declaration['name']
&& (declaration['name'].getText() === 'keys');
}

@@ -39,4 +39,4 @@ import * as ts from 'typescript';

&& (path.join(declaration.getSourceFile().fileName) === indexTs)
&& !!declaration.name
&& (declaration.name.getText() === 'keys');
&& !!declaration['name']
&& (declaration['name'].getText() === 'keys');
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc