@ts-common/json
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,20 +0,17 @@ | ||
export declare namespace Json { | ||
interface ObjectProperties { | ||
readonly [name: string]: Unknown; | ||
} | ||
type Object = object & ObjectProperties; | ||
interface ArrayProperties { | ||
readonly [index: number]: Unknown; | ||
} | ||
type ArrayObject = any[] & ArrayProperties; | ||
type Unknown = null | boolean | string | number | Object | ArrayObject; | ||
interface Visitor<T> { | ||
asNull(): T; | ||
asBoolean(value: boolean): T; | ||
asString(value: string): T; | ||
asNumber(value: number): T; | ||
asObject(value: Object): T; | ||
asArray(value: ReadonlyArray<Unknown>): T; | ||
} | ||
function visit<T>(value: Unknown, visitor: Visitor<T>): T; | ||
export interface ObjectProperties { | ||
readonly [name: string]: Json | undefined; | ||
} | ||
export declare type Object = object & ObjectProperties; | ||
export declare type ArrayObject = Array<any>; | ||
export declare type Json = null | boolean | string | number | Object | ArrayObject; | ||
export interface Visitor<T> { | ||
asNull(): T; | ||
asBoolean(value: boolean): T; | ||
asString(value: string): T; | ||
asNumber(value: number): T; | ||
asObject(value: ObjectProperties): T; | ||
asArray(value: ReadonlyArray<Json>): T; | ||
} | ||
export declare function visit<T>(value: Json, visitor: Visitor<T>): T; | ||
export declare const parse: (str: string) => Json; | ||
export declare const stringify: (json: Json) => string; |
41
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Json; | ||
(function (Json) { | ||
function visit(value, visitor) { | ||
if (value === null) { | ||
return visitor.asNull(); | ||
} | ||
if (typeof value === "boolean") { | ||
return visitor.asBoolean(value); | ||
} | ||
if (typeof value === "string") { | ||
return visitor.asString(value); | ||
} | ||
if (typeof value === "number") { | ||
return visitor.asNumber(value); | ||
} | ||
if (value instanceof Array) { | ||
return visitor.asArray(value); | ||
} | ||
return visitor.asObject(value); | ||
function visit(value, visitor) { | ||
if (value === null) { | ||
return visitor.asNull(); | ||
} | ||
Json.visit = visit; | ||
})(Json = exports.Json || (exports.Json = {})); | ||
if (typeof value === "boolean") { | ||
return visitor.asBoolean(value); | ||
} | ||
if (typeof value === "string") { | ||
return visitor.asString(value); | ||
} | ||
if (typeof value === "number") { | ||
return visitor.asNumber(value); | ||
} | ||
if (value instanceof Array) { | ||
return visitor.asArray(value); | ||
} | ||
return visitor.asObject(value); | ||
} | ||
exports.visit = visit; | ||
exports.parse = JSON.parse; | ||
exports.stringify = JSON.stringify; |
{ | ||
"name": "@ts-common/json", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "JSON Data Type", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
"tsc": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"prepack": "npm install & tsc" | ||
}, | ||
@@ -11,0 +12,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13564
40