
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
embed-json-in-ts
Advanced tools
Natural way of importing json files from TypeScript:
Have a data/data1.json
file in the same folder as your .ts sources and just load it:
import {data1} from './data/data1'
console.log(data1.persons[0].name) // no problems with types - data1 is well described by a typescript interface :)
Problem to solve: As a TypeScript developer I want to import the data inside a .json local file naturally from my TypeScript code. Also I want to make sure it get's embedded in the output (so I can bundle its content)
embed-json-in-js
is a JSON pre-processing tool that convert .json files into real TypeScript modules for easy importing and embedding.
Install:
npm install embed-json-in-ts
Use:
npx embed-json-in-ts --input="src/**/*.json"
npx embed-json-in-ts --mode fs2json --input "./data/**/*.json" --output "src/data" --debug
npx embed-json-in-ts --mode string --input "node_modules/typescript/lib/*.d.ts" --output "./src/typings" --preserveExtension
npm install --save-dev embed-json-in-ts
Use it in your build scripts gulpfile.js
or whatever your build system:
var tool = require('embed-json-in-ts')
tool({input: 'src/**/*.json'})
Basically you want to call embed-json-in-ts before the typescript compiler tsc
for example in package.json:
"scripts": {
"build": "node node_modules/embed-json-in-ts/src/cli --input src/**/data/**/*.json && node node_modules/typescript/bin/tsc",
it will generate a .json file containing a folder contents and then generate the .ts from that:
embed-json-in-ts --mode=fs2json --input="folder/**/*" --output="./data/folder.json"
and then you are ready to:
import {folder} from './data/folder'
*see spec/assets/project-watch-handlebars-test1
tsconfig.json
file (current one - since this is a ts project should have one)FAQs
Natural way of importing json files from TypeScript
The npm package embed-json-in-ts receives a total of 0 weekly downloads. As such, embed-json-in-ts popularity was classified as not popular.
We found that embed-json-in-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.