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

core-types-literals

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

core-types-literals

Convert literal objects in JSON, YAML, or TOML, to core-types

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
155
decreased by-8.28%
Maintainers
1
Weekly downloads
 
Created
Source

core-types-literals

A core-types-compliant reader for literal JSON, YAML, and TOML files. This is useful if you want to generate a TypeScript interface for your literal JSON file, like a locale object using Typeconv.

Usage

Install this package and typeconv:

npm add -D core-types-literals typeconv

Then create a JS file like this:

import { makeConverter, getTypeScriptWriter } from "typeconv";
import { convertYamlToCoreTypes } from "core-types-literals";

/** @returns {import("typeconv").Reader} */
export function getYamlLiteralReader(name) {
  return {
    kind: "yaml",
    read: (x) => convertYamlToCoreTypes(x, name),
  };
}

const { convert } = makeConverter(
  getYamlLiteralReader("MyInterfaceName"),
  getTypeScriptWriter({ warn: console.warn }),
);

const inputYaml = { data: "hello: World" };
const { data: outputTs } = await convert(inputYaml);
console.log(outputTs);
// export interface MyInterfaceName {
//   hello: "World";
// }

Or combine with reading from/writing to files:

// same stuff as above…
import { readFile, writeFile } from "fs/promises";

const inputFileUrl = new URL("../locales/en.yaml", import.meta.url);
const outputTypingsUrl = new URL("./en.i18n.d.ts", import.meta.url);
readFile(i18nFileUrl, "utf8")
  .then((yamlContents) => convert({ data: yamlContents }))
  .then(({ data: tsInterface }) => writeFile(typingsUrl, tsInterface));

License

ISC

Keywords

FAQs

Package last updated on 05 Dec 2023

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

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