New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-creator

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-creator - npm Package Compare versions

Comparing version 1.1.10 to 1.2.0-173bb449

bin/ts-creator

10

dist/types/src/index.d.ts

@@ -1,6 +0,12 @@

/// <reference path="../../../types/prettier.d.ts" />
import * as prettier from 'prettier/standalone';
export declare enum CreatorTarget {
expression = "expression",
runnable = "runnable",
esmodule = "esmodule"
}
export interface Options {
prettierOptions?: Options;
prettierOptions?: prettier.Options;
target?: CreatorTarget;
}
export default function create(code: string, options?: Options): string;
export { transformNode, transformSourceFile } from './transformer';

66

package.json
{
"name": "ts-creator",
"version": "1.1.10",
"version": "1.2.0-173bb449",
"description": "A code generator to generate TypeScript code generator from TypeScript code",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
"types": "dist/types/src/index.d.ts",
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js",
"dev": "webpack --config webpack.config.js",
"test": "webpack --config webpack.test.config.js && node ./dist/tests/index.js",
"lint": "prettier --config ./prettier.json --list-different ./src/**/* ./tests/**/*",
"prettier": "prettier --config ./prettier.json --write ./src/**/* ./tests/**/*"
"build": "cross-env NODE_OPTIONS=--max_old_space_size=4096 NODE_ENV=production webpack --config webpack.config.js",
"dev": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.config.js -w",
"test": "cross-env NODE_OPTIONS=--max_old_space_size=4096 gulp --gulpfile gulpfile.test.js",
"lint": "prettier --config ./prettier.json --list-different ./types/**/* ./src/**/* ./tests/**/* ./gulpfile.test.js ./webpack.config.js ./update-next.js",
"prettier": "prettier --config ./prettier.json --write ./types/**/* ./src/**/* ./tests/**/* ./gulpfile.test.js ./webpack.config.js ./update-next.js",
"coverage": "cross-env NODE_OPTIONS=--max_old_space_size=4096 nyc gulp --gulpfile ./gulpfile.test.js coverage"
},

@@ -17,8 +18,15 @@ "author": "kingwl",

"dependencies": {
"prettier": "^1.15.3",
"typescript": "^3.2.2"
"cardinal": "^2.1.1",
"get-stdin": "^6.0.0",
"prettier": "^1.16.0",
"typescript": "^3.2.2",
"yargs": "^12.0.5"
},
"bin": {
"ts-creator": "bin/ts-creator"
},
"files": [
"src",
"dist",
"bin",
"LICENSE",

@@ -30,10 +38,46 @@ "tsconfig.json",

"devDependencies": {
"@types/get-stdin": "^5.0.1",
"@types/gulp": "^4.0.5",
"@types/gulp-typescript": "^2.13.0",
"@types/memory-fs": "^0.3.2",
"@types/node": "^10.12.18",
"@types/prettier": "^1.15.2",
"@types/webpack-merge": "^4.1.3",
"@types/webpack-stream": "^3.2.10",
"@types/yargs": "^12.0.6",
"cross-env": "^5.2.0",
"codecov": "^3.1.0",
"del": "^3.0.0",
"gulp": "^4.0.0",
"gulp-typescript": "^5.0.0",
"gulp-uglify": "^3.0.1",
"gulp-uglify-es": "^1.0.4",
"istanbul-instrumenter-loader": "^3.0.1",
"memory-fs": "^0.4.1",
"nyc": "^13.2.0",
"require-from-string": "^2.0.2",
"through2": "^3.0.0",
"ts-loader": "^5.3.3",
"uglify-es": "^3.3.9",
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1",
"webpack-merge": "^4.2.1"
"webpack-merge": "^4.2.1",
"webpack-stream": "^5.2.1"
},
"nyc": {
"extension": [
".ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"**/*.d.ts"
],
"reporter": [
"text",
"lcov"
],
"all": true
}
}
}

@@ -1,15 +0,21 @@

# ts-creator
<div align="center">
<img width="520" src="./media/Logo.svg">
# ts-creator
A code generator to generate TypeScript code generator from TypeScript code
A code generator to generate TypeScript code generator from TypeScript code
[![Build Status](https://travis-ci.com/HearTao/ts-creator.svg?branch=master)](https://travis-ci.com/HearTao/ts-creator) [![NPM version](https://img.shields.io/npm/v/ts-creator.svg)](https://www.npmjs.com/package/ts-creator) [![codecov](https://codecov.io/gh/HearTao/ts-creator/branch/master/graph/badge.svg)](https://codecov.io/gh/HearTao/ts-creator)
[![Build Status](https://travis-ci.com/HearTao/ts-creator.svg?branch=master)](https://travis-ci.com/HearTao/ts-creator) [![NPM version](https://img.shields.io/npm/v/ts-creator.svg)](https://www.npmjs.com/package/ts-creator)
👉 [Try It!](https://ts-creator.js.org/) 👈
</div>
[Try It!](https://ts-creator.js.org/)
## How to use it:
```
```shell
npm install ts-creator
```
### 1. generate from code

@@ -98,4 +104,60 @@

## Cli usage
Use `ts-creator` cli to generate code:
```sh
ts-creator <input> [options]
```
Simple usage:
```sh
# print generate code
ts-creator foo.ts
# or read data from pipeline
echo 42 | ts-creator
cat foo.ts | ts-creator
ts-creator < foo.ts
# write to file
ts-creator foo.ts -o foo.js
ts-creator foo.ts > foo.js
```
### Installation
You can install `ts-creator` globally.
```sh
npm i -g ts-creator
# or yarn
yarn global add ts-creator
```
If you install locally, may prepend `npx` or `yarn` you need.
```sh
# use npm
npm i ts-creator
npx ts-creator -h
# use yarn
yarn add ts-creator
yarn ts-creator -h
```
### Cli options
| option | description | type | default |
|---|---|---|---|
| --color | colorful print | boolean | false |
| --output, -o | output to filepath | string | undefined |
| --version, -v | show ts-creator version | boolean | false |
| --help, -h | show help | boolean | false |
## TODO:
- [ ] JSDoc

@@ -43,5 +43,11 @@ import { formatFlags } from './utils'

// NodeFlags.PossiblyContainsDynamicImport, NodeFlags.PossiblyContainsImportMeta, NodeFlags.Ambient, NodeFlags.InWithStatement
const internalFlags: number = 1 << 19 | 1 << 20 | 1 << 22 | 1 << 23
function filterInternalFlags (flags: NodeFlags): NodeFlags {
return flags &= ~internalFlags
}
/** @internal */
export function createNodeFlags(flags: NodeFlags) {
const formattedFlags = formatFlags(flags, NodeFlags).map(f =>
const formattedFlags = formatFlags(filterInternalFlags(flags), NodeFlags).map(f =>
createPropertyAccess(

@@ -52,3 +58,3 @@ createTsAccess(createIdentifier('NodeFlags')),

)
return connectBinary(SyntaxKind.BarBarToken, formattedFlags)
return connectBinary(SyntaxKind.BarToken, formattedFlags)
}

@@ -55,0 +61,0 @@

@@ -1,18 +0,28 @@

///<reference path="../types/prettier.d.ts"/>
import { transformSourceFile, transformNode } from './transformer'
import {
createPrinter,
createSourceFile,
ScriptTarget,
SourceFile
} from 'typescript'
import { transformSourceFile } from './transformer'
import { isDef } from './utils'
import { Options as PrettierOptions, format } from 'prettier'
import { createPrinter, createSourceFile, ScriptTarget } from 'typescript'
import * as prettier from 'prettier/standalone'
import tsPlugin from 'prettier/parser-typescript'
import { resolveRunnable } from './wrapper/runnable'
import { resolveESModule } from './wrapper/esmodule'
// if standalone, that is external module, otherwise undefined
import tsPlugin from 'prettier-typescript-plugins'
export enum CreatorTarget {
expression = 'expression',
runnable = 'runnable',
esmodule = 'esmodule'
}
export interface Options {
prettierOptions?: Options
prettierOptions?: prettier.Options
target?: CreatorTarget
}
const defaultPrettierOptions: PrettierOptions = {
const defaultPrettierOptions: prettier.Options = {
parser: 'typescript',
plugins: [tsPlugin].filter(isDef),
plugins: [tsPlugin],
semi: false,

@@ -28,6 +38,30 @@ singleQuote: true,

function transformRunable(file: SourceFile): SourceFile {
return resolveRunnable(transformNode(file))
}
function transformExpression(file: SourceFile): SourceFile {
return transformSourceFile(file)
}
function transformESModule(file: SourceFile): SourceFile {
return resolveESModule(transformNode(file))
}
function transformTarget(file: SourceFile, options: Options): SourceFile {
switch (options.target) {
case CreatorTarget.runnable:
return transformRunable(file)
case CreatorTarget.esmodule:
return transformESModule(file)
default:
return transformExpression(file)
}
}
export default function create(code: string, options: Options = {}): string {
const printer = createPrinter()
const file = createSourceFile('templory.ts', code, ScriptTarget.Latest)
const factoryFile = transformSourceFile(file)
const factoryFile = transformTarget(file, options)
const factoryCode = printer.printFile(factoryFile)

@@ -39,5 +73,5 @@

}
return format(factoryCode, prettierOptions)
return prettier.format(factoryCode, prettierOptions)
}
export { transformNode, transformSourceFile } from './transformer'

@@ -8,2 +8,3 @@ {

"target": "es5",
"lib": ["es2015"],
"declaration": true,

@@ -10,0 +11,0 @@ "outDir": "./dist",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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