Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

typed-string

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-string

> Use JSON.parse & JSON.stringify safely

Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Typed String

Use JSON.parse & JSON.stringify safely

Usage

import 'typed-string'

/**
 * Get special string type `StringifyFrom<T>` after JSON.stringify.
 */

// const a: StringifyFrom<{ a: number; }>
const a = JSON.stringify({a: 123}) 

/**
 *  Infer parsed object type
 */

// const b: {a: number}
const b = JSON.parse(a) 

/**
 *  It will fallback to any if no types are matched
 */

// const c: any
const c = JSON.parse('"normal string"'); 

// const d: {v: number}
const d = JSON.parse("{v: 123}" as StringifyFrom<{v: number}>); 

It exposes StringifyFrom<T> type to global. StringifyFrom is just string type:

type StringifyFrom<T> = string & {
    toString: () => StringifyFrom<T>;
};

FAQs

Package last updated on 11 Mar 2021

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