npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tjson-js

v0.1.2

Published

Tagged JSON (TJSON): a JSON-based microformat with rich type annotations

Downloads

1,050

Readme

tjson-js npm version Build Status MIT licensed

JavaScript-compatible implementation of Tagged JSON (TJSON), written in TypeScript.

TJSON is a microformat which supplements JSON with an extended set of data types by supplying a type "tag" embedded in object member names:

{
  "array-example:A<O>": [
    {
      "string-example:s": "foobar",
      "binary-example:d": "QklOQVJZ",
      "float-example:f": 0.42,
      "int-example:i": "42",
      "timestamp-example:t": "2016-11-06T22:27:34Z",
      "boolean-example:b": true
    }
  ],
  "set-example:S<i>": [1, 2, 3]
}

Help and Discussion

Have questions? Want to suggest a feature or change?

Requirements

tjson-js is presently targeting ES2017. This is because we soon plan on making use of the TC39 Integer type when it becomes available, and want to make sure users of this library can handle modern ECMAScript versions.

Please make sure your JS runtime is ES2017 compliant, or use a transpiler like babel support older versions of ECMAScript.

Installation

Via npm:

npm install tjson-js

Via Yarn:

yarn install tjson-js

Import TJSON into your project with:

import TJSON from "tjson-js";

API

TJSON.parse()

The TJSON.parse() method parses a TJSON string, returning an Object described by the string. This method is analogous to JavaScript's built-in JSON.parse() method.

TJSON.parse(tjsonString[, decodeUTF8 = true])

Parameters

  • tjsonString: The string to parse, containing data serialized as TJSON.

  • decodeUTF8: instructs whether or not to first decode the TJSON string from UTF-8 before parsing it. By default UTF-8 will be automatically decoded to the engine's internal string representation (e.g. UCS-2). If you would like to skip automatic encoding conversions (e.g. because they happen at the I/O boundary) pass false.

Example

TJSON.parse('{"some-string-data:s":"Hello, world!","some-time-ago:t":"2017-04-22T20:40:53.182Z"}');
// Object { some-string-data: "Hello, world!", some-time-ago: Sat Apr 22 2017 13:40:53 GMT-0700 (PDT) }

TJSON.stringify()

The TJSON.stringify() method converts a JavaScript value to a TJSON string. This method is analogous to JavaScript's built-in JSON.stringify() method.

TJSON.stringify(value[, space = 0[, encodeUTF8 = true]])

Parameters

  • value: The value to convert to a TJSON string.

  • space: a String or Number object that's to insert white space into the output JSON string for readability purposes. For more information, please see the JSON.stringify() documentation.

  • encodeUTF8: instructs whether or not to encode the resulting document as UTF-8. The TJSON specification requires all confirming documents are encoded as UTF-8. If you would like to skip automatic encoding conversions (e.g. because they happen at the I/O boundary) pass false.

Type Conversions

The table below shows how TJSON tags map to JavaScript types:

| Tag | JavaScript Type | Notes | |-----|-----------------|-----------------------------------------------| | O | Object | | | A | Array | | | S | Set | | | b | Boolean | | | d | Uint8Array | | | f | Number | | | i | Number | Will switch to TC39 Integer when available | | u | Number | Will switch to TC39 Integer when available | | s | String | | | t | Date | |

TJSON Spec Deviations

This is not (yet) a fully compliant TJSON parser. It contains the following defects, which can also be found in tjson.spec.ts's skipped examples:

  • 64-bit integer range unsupported: can't be supported in JavaScript until the TC39 Integer type is available.
  • Repeated JSON object member names tolerated: the spec mandates that the names of JSON object members must be unique. This implementation silently ignores them.
  • Set uniqueness not guaranteed: the spec mandates that all members of sets must be unique. Unfortunately JavaScript's Set type and equality semantics allow members that are identical if compared by value.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tjson/tjson-js

License

Copyright (c) 2017 Tony Arcieri. Distributed under the MIT License. See LICENSE.txt for further details.