New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

tsc-macro

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsc-macro

Compose macro in Typescript, expand back into Typescript

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

tsc-macro

Compose macro in Typescript, expand back into Typescript

npm Package Version

How it works

tsc-macro evaluates each [name].macro.ts file and save the result to corresponding [name].ts

Example

Source file: fruit.macro.ts

import { genEnum } from 'tsc-macro'

genEnum('fruit', ['apple', 'orange'])

Generated file: fruit.ts

export enum fruit {
  apple,
  orange,
}

A more flexible example: color.macro.ts

import { genArray, genUnionType } from 'tsc-macro'

let colors = ['red', 'green', 'blue']

;`
${genUnionType('Color', colors)}

${genArray('values', colors)}

export const colors: Color[] = ${genArray(colors)}
`.trim()

Generated into color.ts

export type Color =
  | 'red'
  | 'green'
  | 'blue'

export const values = [
  'red',
  'green',
  'blue',
]

export const colors: Color[] = [
  'red',
  'green',
  'blue',
]

More Examples

Installation

npm i -D tsc-macro

Transpile

## recursively in the current directory
npx tsc-macro

## recursively in given directory
npx tsc-macro src/models

License

This project is licensed with BSD-2-Clause

This is free, libre, and open-source software. It comes down to four essential freedoms [ref]:

  • The freedom to run the program as you wish, for any purpose
  • The freedom to study how the program works, and change it so it does your computing as you wish
  • The freedom to redistribute copies so you can help others
  • The freedom to distribute copies of your modified versions to others

Keywords

typescript

FAQs

Package last updated on 15 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts