
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
definition
Advanced tools
Generate typescript type definitions and enumerations from business definition json records.
Generate typescript type definitions and enumerations from business definition json records.
npm i definition
definition.config.mjs
/**
* @return {import('definition').ConfigOptions}
*/
export default () => {
return {
dir: "./jsons",
output: "./definitions",
};
};
See ConfigOptions Options for details.
./jsons/hello.json
[
{ "key": "hello-1", "value": "hello", "label": "cba" },
{ "key": "hello-2", "value": "hello2", "label": "cba2" }
]
Records is extendable, for example { "key": "hello-1", "value": "hello", "label": "cba", "createBy": "god" }, is okay.
value should be string or number.
key and value are required, and key can be customized via the configuration file.
npx def generate # or npx def g
or add command to scripts with npm run
{
"scripts": {
"definition": "def generate" // or def g
}
}
definitions
├── hello.ts
└── utils
├── index.ts
├── kr-map.ts
├── kv-map.ts
├── types.ts
└── vr-map.ts
./definitions/hello.ts
import { krMap, vrMap, kvMap } from "../utils";
export const ROUTES_records_readonly = [{ "key": "hello-1", "value": "hello", "label": "cba" }, { "key": "hello-2", "value": "hello2", "label": "cba2" }] as const;
export const ROUTES_records = ROUTES_records_readonly.concat(); // mutable records
export type ROUTES_Records = typeof ROUTES_records_readonly; // record type
export type ROUTES_Values = ROUTES_Records[number]["value"]; // values's type
export const ROUTES_Keys = {
Hello1: "Hello1",
Hello2: "Hello2"
} as const;
export const ROUTES_key_list = [ROUTES_Keys.Hello1, ROUTES_Keys.Hello2] as const; // key list
export const ROUTES_kr = krMap(ROUTES_records_readonly, ROUTES_key_list); // key -> record map
export const ROUTES_vr = vrMap(ROUTES_records_readonly, ROUTES_key_list, "value"); // value -> record map
export const ROUTES_kv = kvMap(ROUTES_records_readonly, ROUTES_key_list, "value"); // key -> value map
Usage: cli [options] [command]
Options:
-h, --help display help for command
Commands:
generate|g [options]
help [command] display help for command
command generate
sage: cli generate|g [options]
Options:
-c, --config [path] Config file path
-h, --help display help for command
interface ConfigOptions {
dir: string; // Json records directory
output: string; // Definitions output directory
valueField?: string; // The value field key
keyField?: string; // The key field key
keyFormat?: "camelback" | "camelcase" | "underscore"; // The format of the generated key
keyGen?: (record: Record<string, any>) => string; // Custom key generate function
}
Note: when keyGen is configured, keyFormat will be ignored.
MIT
FAQs
Generate typescript type definitions and enumerations from business definition json records.
The npm package definition receives a total of 19 weekly downloads. As such, definition popularity was classified as not popular.
We found that definition demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.