cktjs
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

cktjs

cktjs is an implementation of a decoder and encoder for the CKT config language. It aims to be a drop-in replacement for JavaScripts's built in JSON library minus support for reviver and replacer.

For syntax highlighting try the cktvs extension for Visual Studio Code.

Installation

The cktjs npm package provides the original ES module source plus CommonJS and browser IIFE builds. It can be installed with:

npm install cktjs

For Deno users, you can get the module from deno.land/x/cktjs:

import * as CKT from "https://deno.land/x/cktjs@1.0/mod.ts";

If you're working with a browser, you can use the IIFE build directly from a CDN. Currently, cktjs officially supports unpkg and jsdelivr:

<!-- unpkg -->
<script src="https://www.unpkg.com/cktjs@1.0"></script>
<!-- jsdelivr -->
<script src="https://cdn.jsdelivr.net/npm/cktjs@1.0"></script>

Usage

Import cktjs

// CommonJS
const CKT = require("cktjs");
// ESModules
import * as CKT from "cktjs";

Parse a CKT document

const config = CKT.parse(`
rate limits = [
  /* = [
    request limit = 100
    window length = 2s
  ]
  /api/upload = [
    size limit = 100mb
    request limit = 6
    window length = 5s
  ]
]
`);
{
  "rate limits": {
    "/*": {
      "request limit": 100,
      "window length": "2s"
    },
    "/api/upload": {
      "size limit": "100mb",
      "request limit": 6,
      "window length": "5s"
    }
  }
}

Encode an object as a CKT document

const menu = {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      { "value": "New"  , "onclick": "CreateNewDoc()" },
      { "value": "Open" , "onclick": "OpenDoc()"      },
      { "value": "Close", "onclick": "CloseDoc()"     },
    ],
  },
};
const text = CKT.stringify(menu, 2);
id = file
value = File
popup = [
  menuitem = [
    [
      value = New
      onclick = "CreateNewDoc()"
    ]
    [
      value = Open
      onclick = "OpenDoc()"
    ]
    [
      value = Close
      onclick = "CloseDoc()"
    ]
  ]
]

Authors

Made with by Lua MacDougall (foxgirl.dev)

License

This project is licensed under the MIT license.

Dependents (0)

Package Sidebar

Install

npm i cktjs

Weekly Downloads

3

Version

1.0.5

License

MIT

Unpacked Size

51.6 kB

Total Files

12

Last publish

Collaborators

  • luavixen