parse-json-object
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -1,3 +0,7 @@ | ||
import { isJSONObject, JSONObject, JSONValue, JSONArray } from "types-json"; | ||
export default function parse<T extends JSONObject>(text?: string): T | undefined; | ||
export { isJSONObject, JSONObject, JSONValue, JSONArray }; | ||
import { JSONObject, JSONValue, JSONArray } from "types-json"; | ||
export declare function parse<T extends JSONValue>(text: string | undefined, isType: (value?: T) => boolean): T | undefined; | ||
export declare function parseJSONValue<T extends JSONValue>(text?: string): T | undefined; | ||
export declare function parseJSONObject<T extends JSONObject>(text?: string): T | undefined; | ||
export declare function parseJSONArray<T extends JSONArray>(text?: string): T | undefined; | ||
export declare function parseString<T extends string>(text?: string): T | undefined; | ||
export * from "types-json"; |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = parse; | ||
var _exportNames = { | ||
parse: true, | ||
parseJSONValue: true, | ||
parseJSONObject: true, | ||
parseJSONArray: true, | ||
parseString: true | ||
}; | ||
exports.parse = parse; | ||
exports.parseJSONValue = parseJSONValue; | ||
exports.parseJSONObject = parseJSONObject; | ||
exports.parseJSONArray = parseJSONArray; | ||
exports.parseString = parseString; | ||
var _typesJson = require("types-json"); | ||
exports.isJSONObject = _typesJson.isJSONObject; | ||
exports.JSONObject = _typesJson.JSONObject; | ||
exports.JSONValue = _typesJson.JSONValue; | ||
exports.JSONArray = _typesJson.JSONArray; | ||
Object.keys(_typesJson).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
exports[key] = _typesJson[key]; | ||
}); | ||
function parse(text) { | ||
function parse(text, isType) { | ||
if (text) { | ||
@@ -18,3 +30,3 @@ try { | ||
if ((0, _typesJson.isJSONObject)(json)) { | ||
if (isType(json)) { | ||
return json; | ||
@@ -30,2 +42,18 @@ } else { | ||
} | ||
} | ||
function parseJSONValue(text) { | ||
return parse(text, _typesJson.isJSONValue); | ||
} | ||
function parseJSONObject(text) { | ||
return parse(text, _typesJson.isJSONObject); | ||
} | ||
function parseJSONArray(text) { | ||
return parse(text, _typesJson.isJSONArray); | ||
} | ||
function parseString(text) { | ||
return parse(text, _typesJson.isString); | ||
} |
{ | ||
"name": "parse-json-object", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Parse a typed JSON object.", | ||
@@ -30,10 +30,12 @@ "license": "MIT", | ||
"postversion": "git push", | ||
"prepublishOnly": "yarn build" | ||
"prepublishOnly": "yarn build && yarn test", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"types-json": "^1.0.6" | ||
"types-json": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@bconnorwhite/bob": "^2.0.1" | ||
"@bconnorwhite/bob": "^2.1.0", | ||
"jest": "^26.4.2" | ||
} | ||
} |
@@ -39,3 +39,7 @@ <div align="center"> | ||
import parse, { | ||
isJSONObject, | ||
parseJSONValue, | ||
parseJSONObject, | ||
parseJSONArray, | ||
parseString, | ||
JSONValue, | ||
JSONObject, | ||
@@ -46,6 +50,14 @@ JSONValue, | ||
function parse<T extends JSONObject>(json?: string) => T | undefined; | ||
function parse<T extends JSONValue>(value: string | undefined, isType: (value: T) => boolean): T | undefined; | ||
function isJSONObject(object?: JSONValue): object is JSONObject; | ||
function parseJSONValue<T extends JSONValue>(value?: string): T | undefined; | ||
function parseJSONObject<T extends JSONObject>(value?: string): T | undefined; | ||
function parseJSONArray<T extends JSONArray>(value?: string): T | undefined; | ||
function parseString<T extends string>(value?: string): T | undefined; | ||
type JSONValue = string | number | boolean | null | JSONObject | JSONArray; | ||
type JSONObject = { | ||
@@ -55,4 +67,2 @@ [key in string]?: JSONValue | ||
type JSONValue = string | number | boolean | null | JSONObject | JSONArray; | ||
interface JSONArray extends Array<JSONValue> {}; | ||
@@ -59,0 +69,0 @@ ``` |
5292
54
91
2
Updatedtypes-json@^1.2.0