🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

transcribe-json

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

transcribe-json

From JSON file to object. Extract any fields. From object to JS/JSON file.

latest
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

transcribe-json

  • From JSON file to object.
  • Extract any fields.
  • From object to JSON/JavaScript file.

Install

npm install transcribe-json

Usage

API

Three basic functions:

import { read, extract, write } from "transcribe-json";
  • read is async and returns the JSON file content as an object.
  • extract returns a function that extracts fields from any object (only top-level fields can be specified).
  • write returns an async function that write an object to a file in JSON, ES Module or CommonJS.

You can combine them as follows:

// just read and use it as you like later
const content = await read(srcfile);

// copy all fields to another file
read(srcfile).then(write(outfile));

// extract some fields
read(srcfile).then(extract(fields)).then(write(outfile));

// insert any callback to convert an object to another
read(srcfile).then(convert).then(write(outfile));

There are also some options for write():

write(outfile, {
  replacer: null,   // used in JSON.stringify()
  space: "  ",      // used in JSON.stringify()
  filetype: "json", // "json", "mjs" or "cjs"
  formatter: (code, filetype) => code, // any formatting function
});

If filetype === "mjs", the result will be a default export.

export default {
  "name": "transcribe-json",
  "version": "0.1.0-alpha"
};

CLI

Use transcribe-json command.

Command:
  transcribe-json [options] <input filepath>
  transcribe-json <-h|--help|-v|--version>
Options:
  --outfile <path>  The output filepath with or without extension. (required)
  --type <type>     The filetype to emit. Either json, mjs or cjs. (optional)
  --fields <names>  Top-level field names to extract. Comma separated. (optional)

For example in your package.json:

{
  "scripts": {
    "pkg": "transcribe-json package.json --outfile package-info.js --type mjs --fields name,version"
  }
}

Keywords

json

FAQs

Package last updated on 11 Feb 2021

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