Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.
/ typeon Public archive

✔️ Typed JSON parse and stringify for TypeScript

License

Notifications You must be signed in to change notification settings

deepsweet/typeon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typeon

⚠️ Project has been transferred to NexTools metarepo

npm tests coverage

Typed JSON parse and stringify for TypeScript.

  • no any
  • no additional arguments for parse and stringify

Requirements

  • Node.js >= 8.6.0

Install

yarn add --dev typeon
# or
npm install --dev typeon

Usage

import {
  jsonParse,
  jsonStringify,
  TJsonValue,
  TJsonMap,
  TJsonArray
} from 'typeon'

const json = jsonParse('{"a":{"b":["c"]}}') // TJsonMap
const str = jsonStringify({ a: { b: ['c'] } }) // string

const jsonValueString: TJsonValue = 'a' // ok
const jsonValueNumber: TJsonValue = 1 // ok
const jsonValueBoolean: TJsonValue = true // ok
const jsonValueNull: TJsonValue = null // ok
const jsonValueObject: TJsonValue = {} // ok
const jsonValueArray: TJsonValue = [] // ok
const jsonValueUndefined: TJsonValue = undefined // error
const jsonValueFunction: TJsonValue = () => {} // error
const jsonValueRegexp: TJsonValue = /^.$/ // error
// …

const jsonMap: TJsonMap = { a: true } // ok
const jsonMapWithFunction: TJsonMap = { a: () => {} } // error
// …

const jsonArray: TJsonArray = [1] // ok
const jsonArrayWithFunction: TJsonArray = [() => {}] // error
// …