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

typeon

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeon

Typed JSON parse and stringify for TypeScript

2.0.0
latest
Source
npm
Version published
Weekly downloads
84K
8.28%
Maintainers
3
Weekly downloads
 
Created
Source

typeon npm

Typed JSON parse and stringify for TypeScript.

  • no any
  • no additional arguments for parse and stringify

Install

yarn add --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
// …

Keywords

typescript

FAQs

Package last updated on 14 Aug 2020

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