Comparing version 1.13.3 to 1.13.4-0
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.setDeep = exports.getDeep = void 0; | ||
var is_1 = require("./is"); | ||
var util_1 = require("./util"); | ||
import { isMap, isArray, isPlainObject, isSet } from './is.js'; | ||
import { includes } from './util.js'; | ||
var getNthKey = function (value, n) { | ||
@@ -15,20 +12,20 @@ var keys = value.keys(); | ||
function validatePath(path) { | ||
if (util_1.includes(path, '__proto__')) { | ||
if (includes(path, '__proto__')) { | ||
throw new Error('__proto__ is not allowed as a property'); | ||
} | ||
if (util_1.includes(path, 'prototype')) { | ||
if (includes(path, 'prototype')) { | ||
throw new Error('prototype is not allowed as a property'); | ||
} | ||
if (util_1.includes(path, 'constructor')) { | ||
if (includes(path, 'constructor')) { | ||
throw new Error('constructor is not allowed as a property'); | ||
} | ||
} | ||
var getDeep = function (object, path) { | ||
export var getDeep = function (object, path) { | ||
validatePath(path); | ||
for (var i = 0; i < path.length; i++) { | ||
var key = path[i]; | ||
if (is_1.isSet(object)) { | ||
if (isSet(object)) { | ||
object = getNthKey(object, +key); | ||
} | ||
else if (is_1.isMap(object)) { | ||
else if (isMap(object)) { | ||
var row = +key; | ||
@@ -52,4 +49,3 @@ var type = +path[++i] === 0 ? 'key' : 'value'; | ||
}; | ||
exports.getDeep = getDeep; | ||
var setDeep = function (object, path, mapper) { | ||
export var setDeep = function (object, path, mapper) { | ||
validatePath(path); | ||
@@ -62,14 +58,14 @@ if (path.length === 0) { | ||
var key = path[i]; | ||
if (is_1.isArray(parent)) { | ||
if (isArray(parent)) { | ||
var index = +key; | ||
parent = parent[index]; | ||
} | ||
else if (is_1.isPlainObject(parent)) { | ||
else if (isPlainObject(parent)) { | ||
parent = parent[key]; | ||
} | ||
else if (is_1.isSet(parent)) { | ||
else if (isSet(parent)) { | ||
var row = +key; | ||
parent = getNthKey(parent, row); | ||
} | ||
else if (is_1.isMap(parent)) { | ||
else if (isMap(parent)) { | ||
var isEnd = i === path.length - 2; | ||
@@ -93,9 +89,9 @@ if (isEnd) { | ||
var lastKey = path[path.length - 1]; | ||
if (is_1.isArray(parent)) { | ||
if (isArray(parent)) { | ||
parent[+lastKey] = mapper(parent[+lastKey]); | ||
} | ||
else if (is_1.isPlainObject(parent)) { | ||
else if (isPlainObject(parent)) { | ||
parent[lastKey] = mapper(parent[lastKey]); | ||
} | ||
if (is_1.isSet(parent)) { | ||
if (isSet(parent)) { | ||
var oldValue = getNthKey(parent, +lastKey); | ||
@@ -108,3 +104,3 @@ var newValue = mapper(oldValue); | ||
} | ||
if (is_1.isMap(parent)) { | ||
if (isMap(parent)) { | ||
var row = +path[path.length - 2]; | ||
@@ -130,3 +126,2 @@ var keyToRow = getNthKey(parent, row); | ||
}; | ||
exports.setDeep = setDeep; | ||
//# sourceMappingURL=accessDeep.js.map |
@@ -1,3 +0,3 @@ | ||
import { Registry } from './registry'; | ||
import { Class } from './types'; | ||
import { Registry } from './registry.js'; | ||
import { Class } from './types.js'; | ||
export interface RegisterOptions { | ||
@@ -4,0 +4,0 @@ identifier?: string; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -17,5 +16,3 @@ var extendStatics = function (d, b) { | ||
})(); | ||
exports.__esModule = true; | ||
exports.ClassRegistry = void 0; | ||
var registry_1 = require("./registry"); | ||
import { Registry } from './registry.js'; | ||
var ClassRegistry = /** @class */ (function (_super) { | ||
@@ -43,4 +40,4 @@ __extends(ClassRegistry, _super); | ||
return ClassRegistry; | ||
}(registry_1.Registry)); | ||
exports.ClassRegistry = ClassRegistry; | ||
}(Registry)); | ||
export { ClassRegistry }; | ||
//# sourceMappingURL=class-registry.js.map |
@@ -1,2 +0,2 @@ | ||
import { JSONValue } from './types'; | ||
import { JSONValue } from './types.js'; | ||
export interface CustomTransfomer<I, O extends JSONValue> { | ||
@@ -3,0 +3,0 @@ name: string; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.CustomTransformerRegistry = void 0; | ||
var util_1 = require("./util"); | ||
import { find } from './util.js'; | ||
var CustomTransformerRegistry = /** @class */ (function () { | ||
@@ -13,3 +10,3 @@ function CustomTransformerRegistry() { | ||
CustomTransformerRegistry.prototype.findApplicable = function (v) { | ||
return util_1.find(this.transfomers, function (transformer) { | ||
return find(this.transfomers, function (transformer) { | ||
return transformer.isApplicable(v); | ||
@@ -23,3 +20,3 @@ }); | ||
}()); | ||
exports.CustomTransformerRegistry = CustomTransformerRegistry; | ||
export { CustomTransformerRegistry }; | ||
//# sourceMappingURL=custom-transformer-registry.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.DoubleIndexedKV = void 0; | ||
var DoubleIndexedKV = /** @class */ (function () { | ||
@@ -25,3 +22,3 @@ function DoubleIndexedKV() { | ||
}()); | ||
exports.DoubleIndexedKV = DoubleIndexedKV; | ||
export { DoubleIndexedKV }; | ||
//# sourceMappingURL=double-indexed-kv.js.map |
@@ -1,5 +0,5 @@ | ||
import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types'; | ||
import { ClassRegistry, RegisterOptions } from './class-registry'; | ||
import { Registry } from './registry'; | ||
import { CustomTransfomer, CustomTransformerRegistry } from './custom-transformer-registry'; | ||
import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types.js'; | ||
import { ClassRegistry, RegisterOptions } from './class-registry.js'; | ||
import { Registry } from './registry.js'; | ||
import { CustomTransfomer, CustomTransformerRegistry } from './custom-transformer-registry.js'; | ||
export default class SuperJSON { | ||
@@ -6,0 +6,0 @@ /** |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -34,9 +33,7 @@ __assign = Object.assign || function(t) { | ||
}; | ||
exports.__esModule = true; | ||
exports.allowErrorProps = exports.registerSymbol = exports.registerCustom = exports.registerClass = exports.parse = exports.stringify = exports.deserialize = exports.serialize = exports.SuperJSON = void 0; | ||
var class_registry_1 = require("./class-registry"); | ||
var registry_1 = require("./registry"); | ||
var custom_transformer_registry_1 = require("./custom-transformer-registry"); | ||
var plainer_1 = require("./plainer"); | ||
var copy_anything_1 = require("copy-anything"); | ||
import { ClassRegistry } from './class-registry.js'; | ||
import { Registry } from './registry.js'; | ||
import { CustomTransformerRegistry, } from './custom-transformer-registry.js'; | ||
import { applyReferentialEqualityAnnotations, applyValueAnnotations, generateReferentialEqualityAnnotations, walker, } from './plainer.js'; | ||
import { copy } from 'copy-anything'; | ||
var SuperJSON = /** @class */ (function () { | ||
@@ -48,5 +45,5 @@ /** | ||
var _b = _a === void 0 ? {} : _a, _c = _b.dedupe, dedupe = _c === void 0 ? false : _c; | ||
this.classRegistry = new class_registry_1.ClassRegistry(); | ||
this.symbolRegistry = new registry_1.Registry(function (s) { var _a; return (_a = s.description) !== null && _a !== void 0 ? _a : ''; }); | ||
this.customTransformerRegistry = new custom_transformer_registry_1.CustomTransformerRegistry(); | ||
this.classRegistry = new ClassRegistry(); | ||
this.symbolRegistry = new Registry(function (s) { var _a; return (_a = s.description) !== null && _a !== void 0 ? _a : ''; }); | ||
this.customTransformerRegistry = new CustomTransformerRegistry(); | ||
this.allowedErrorProps = []; | ||
@@ -57,3 +54,3 @@ this.dedupe = dedupe; | ||
var identities = new Map(); | ||
var output = plainer_1.walker(object, identities, this, this.dedupe); | ||
var output = walker(object, identities, this, this.dedupe); | ||
var res = { | ||
@@ -65,3 +62,3 @@ json: output.transformedValue | ||
} | ||
var equalityAnnotations = plainer_1.generateReferentialEqualityAnnotations(identities, this.dedupe); | ||
var equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe); | ||
if (equalityAnnotations) { | ||
@@ -74,8 +71,8 @@ res.meta = __assign(__assign({}, res.meta), { referentialEqualities: equalityAnnotations }); | ||
var json = payload.json, meta = payload.meta; | ||
var result = copy_anything_1.copy(json); | ||
var result = copy(json); | ||
if (meta === null || meta === void 0 ? void 0 : meta.values) { | ||
result = plainer_1.applyValueAnnotations(result, meta.values, this); | ||
result = applyValueAnnotations(result, meta.values, this); | ||
} | ||
if (meta === null || meta === void 0 ? void 0 : meta.referentialEqualities) { | ||
result = plainer_1.applyReferentialEqualityAnnotations(result, meta.referentialEqualities); | ||
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities); | ||
} | ||
@@ -118,12 +115,12 @@ return result; | ||
}()); | ||
exports.SuperJSON = SuperJSON; | ||
exports["default"] = SuperJSON; | ||
exports.serialize = SuperJSON.serialize; | ||
exports.deserialize = SuperJSON.deserialize; | ||
exports.stringify = SuperJSON.stringify; | ||
exports.parse = SuperJSON.parse; | ||
exports.registerClass = SuperJSON.registerClass; | ||
exports.registerCustom = SuperJSON.registerCustom; | ||
exports.registerSymbol = SuperJSON.registerSymbol; | ||
exports.allowErrorProps = SuperJSON.allowErrorProps; | ||
export default SuperJSON; | ||
export { SuperJSON }; | ||
export var serialize = SuperJSON.serialize; | ||
export var deserialize = SuperJSON.deserialize; | ||
export var stringify = SuperJSON.stringify; | ||
export var parse = SuperJSON.parse; | ||
export var registerClass = SuperJSON.registerClass; | ||
export var registerCustom = SuperJSON.registerCustom; | ||
export var registerSymbol = SuperJSON.registerSymbol; | ||
export var allowErrorProps = SuperJSON.allowErrorProps; | ||
//# sourceMappingURL=index.js.map |
@@ -1,14 +0,9 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.isURL = exports.isTypedArray = exports.isInfinite = exports.isBigint = exports.isPrimitive = exports.isNaNValue = exports.isError = exports.isDate = exports.isSymbol = exports.isSet = exports.isMap = exports.isRegExp = exports.isBoolean = exports.isNumber = exports.isString = exports.isArray = exports.isEmptyObject = exports.isPlainObject = exports.isNull = exports.isUndefined = void 0; | ||
var getType = function (payload) { | ||
return Object.prototype.toString.call(payload).slice(8, -1); | ||
}; | ||
var isUndefined = function (payload) { | ||
export var isUndefined = function (payload) { | ||
return typeof payload === 'undefined'; | ||
}; | ||
exports.isUndefined = isUndefined; | ||
var isNull = function (payload) { return payload === null; }; | ||
exports.isNull = isNull; | ||
var isPlainObject = function (payload) { | ||
export var isNull = function (payload) { return payload === null; }; | ||
export var isPlainObject = function (payload) { | ||
if (typeof payload !== 'object' || payload === null) | ||
@@ -22,74 +17,56 @@ return false; | ||
}; | ||
exports.isPlainObject = isPlainObject; | ||
var isEmptyObject = function (payload) { | ||
return exports.isPlainObject(payload) && Object.keys(payload).length === 0; | ||
export var isEmptyObject = function (payload) { | ||
return isPlainObject(payload) && Object.keys(payload).length === 0; | ||
}; | ||
exports.isEmptyObject = isEmptyObject; | ||
var isArray = function (payload) { | ||
export var isArray = function (payload) { | ||
return Array.isArray(payload); | ||
}; | ||
exports.isArray = isArray; | ||
var isString = function (payload) { | ||
export var isString = function (payload) { | ||
return typeof payload === 'string'; | ||
}; | ||
exports.isString = isString; | ||
var isNumber = function (payload) { | ||
export var isNumber = function (payload) { | ||
return typeof payload === 'number' && !isNaN(payload); | ||
}; | ||
exports.isNumber = isNumber; | ||
var isBoolean = function (payload) { | ||
export var isBoolean = function (payload) { | ||
return typeof payload === 'boolean'; | ||
}; | ||
exports.isBoolean = isBoolean; | ||
var isRegExp = function (payload) { | ||
export var isRegExp = function (payload) { | ||
return payload instanceof RegExp; | ||
}; | ||
exports.isRegExp = isRegExp; | ||
var isMap = function (payload) { | ||
export var isMap = function (payload) { | ||
return payload instanceof Map; | ||
}; | ||
exports.isMap = isMap; | ||
var isSet = function (payload) { | ||
export var isSet = function (payload) { | ||
return payload instanceof Set; | ||
}; | ||
exports.isSet = isSet; | ||
var isSymbol = function (payload) { | ||
export var isSymbol = function (payload) { | ||
return getType(payload) === 'Symbol'; | ||
}; | ||
exports.isSymbol = isSymbol; | ||
var isDate = function (payload) { | ||
export var isDate = function (payload) { | ||
return payload instanceof Date && !isNaN(payload.valueOf()); | ||
}; | ||
exports.isDate = isDate; | ||
var isError = function (payload) { | ||
export var isError = function (payload) { | ||
return payload instanceof Error; | ||
}; | ||
exports.isError = isError; | ||
var isNaNValue = function (payload) { | ||
export var isNaNValue = function (payload) { | ||
return typeof payload === 'number' && isNaN(payload); | ||
}; | ||
exports.isNaNValue = isNaNValue; | ||
var isPrimitive = function (payload) { | ||
return exports.isBoolean(payload) || | ||
exports.isNull(payload) || | ||
exports.isUndefined(payload) || | ||
exports.isNumber(payload) || | ||
exports.isString(payload) || | ||
exports.isSymbol(payload); | ||
export var isPrimitive = function (payload) { | ||
return isBoolean(payload) || | ||
isNull(payload) || | ||
isUndefined(payload) || | ||
isNumber(payload) || | ||
isString(payload) || | ||
isSymbol(payload); | ||
}; | ||
exports.isPrimitive = isPrimitive; | ||
var isBigint = function (payload) { | ||
export var isBigint = function (payload) { | ||
return typeof payload === 'bigint'; | ||
}; | ||
exports.isBigint = isBigint; | ||
var isInfinite = function (payload) { | ||
export var isInfinite = function (payload) { | ||
return payload === Infinity || payload === -Infinity; | ||
}; | ||
exports.isInfinite = isInfinite; | ||
var isTypedArray = function (payload) { | ||
export var isTypedArray = function (payload) { | ||
return ArrayBuffer.isView(payload) && !(payload instanceof DataView); | ||
}; | ||
exports.isTypedArray = isTypedArray; | ||
var isURL = function (payload) { return payload instanceof URL; }; | ||
exports.isURL = isURL; | ||
export var isURL = function (payload) { return payload instanceof URL; }; | ||
//# sourceMappingURL=is.js.map |
@@ -1,14 +0,9 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.parsePath = exports.stringifyPath = exports.escapeKey = void 0; | ||
var escapeKey = function (key) { return key.replace(/\./g, '\\.'); }; | ||
exports.escapeKey = escapeKey; | ||
var stringifyPath = function (path) { | ||
export var escapeKey = function (key) { return key.replace(/\./g, '\\.'); }; | ||
export var stringifyPath = function (path) { | ||
return path | ||
.map(String) | ||
.map(exports.escapeKey) | ||
.map(escapeKey) | ||
.join('.'); | ||
}; | ||
exports.stringifyPath = stringifyPath; | ||
var parsePath = function (string) { | ||
export var parsePath = function (string) { | ||
var result = []; | ||
@@ -36,3 +31,2 @@ var segment = ''; | ||
}; | ||
exports.parsePath = parsePath; | ||
//# sourceMappingURL=pathstringifier.js.map |
@@ -1,3 +0,3 @@ | ||
import { TypeAnnotation } from './transformer'; | ||
import SuperJSON from '.'; | ||
import { TypeAnnotation } from './transformer.js'; | ||
import SuperJSON from './index.js'; | ||
declare type Tree<T> = InnerNode<T> | Leaf<T>; | ||
@@ -4,0 +4,0 @@ declare type Leaf<T> = [T]; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
@@ -23,10 +22,8 @@ var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
}; | ||
exports.__esModule = true; | ||
exports.walker = exports.generateReferentialEqualityAnnotations = exports.applyReferentialEqualityAnnotations = exports.applyValueAnnotations = void 0; | ||
var is_1 = require("./is"); | ||
var pathstringifier_1 = require("./pathstringifier"); | ||
var transformer_1 = require("./transformer"); | ||
var util_1 = require("./util"); | ||
var pathstringifier_2 = require("./pathstringifier"); | ||
var accessDeep_1 = require("./accessDeep"); | ||
import { isArray, isEmptyObject, isMap, isPlainObject, isPrimitive, isSet, } from './is.js'; | ||
import { escapeKey, stringifyPath } from './pathstringifier.js'; | ||
import { isInstanceOfRegisteredClass, transformValue, untransformValue, } from './transformer.js'; | ||
import { includes, forEach } from './util.js'; | ||
import { parsePath } from './pathstringifier.js'; | ||
import { getDeep, setDeep } from './accessDeep.js'; | ||
function traverse(tree, walker, origin) { | ||
@@ -37,5 +34,5 @@ if (origin === void 0) { origin = []; } | ||
} | ||
if (!is_1.isArray(tree)) { | ||
util_1.forEach(tree, function (subtree, key) { | ||
return traverse(subtree, walker, __spreadArray(__spreadArray([], __read(origin)), __read(pathstringifier_2.parsePath(key)))); | ||
if (!isArray(tree)) { | ||
forEach(tree, function (subtree, key) { | ||
return traverse(subtree, walker, __spreadArray(__spreadArray([], __read(origin)), __read(parsePath(key)))); | ||
}); | ||
@@ -46,4 +43,4 @@ return; | ||
if (children) { | ||
util_1.forEach(children, function (child, key) { | ||
traverse(child, walker, __spreadArray(__spreadArray([], __read(origin)), __read(pathstringifier_2.parsePath(key)))); | ||
forEach(children, function (child, key) { | ||
traverse(child, walker, __spreadArray(__spreadArray([], __read(origin)), __read(parsePath(key)))); | ||
}); | ||
@@ -53,37 +50,35 @@ } | ||
} | ||
function applyValueAnnotations(plain, annotations, superJson) { | ||
export function applyValueAnnotations(plain, annotations, superJson) { | ||
traverse(annotations, function (type, path) { | ||
plain = accessDeep_1.setDeep(plain, path, function (v) { return transformer_1.untransformValue(v, type, superJson); }); | ||
plain = setDeep(plain, path, function (v) { return untransformValue(v, type, superJson); }); | ||
}); | ||
return plain; | ||
} | ||
exports.applyValueAnnotations = applyValueAnnotations; | ||
function applyReferentialEqualityAnnotations(plain, annotations) { | ||
export function applyReferentialEqualityAnnotations(plain, annotations) { | ||
function apply(identicalPaths, path) { | ||
var object = accessDeep_1.getDeep(plain, pathstringifier_2.parsePath(path)); | ||
identicalPaths.map(pathstringifier_2.parsePath).forEach(function (identicalObjectPath) { | ||
plain = accessDeep_1.setDeep(plain, identicalObjectPath, function () { return object; }); | ||
var object = getDeep(plain, parsePath(path)); | ||
identicalPaths.map(parsePath).forEach(function (identicalObjectPath) { | ||
plain = setDeep(plain, identicalObjectPath, function () { return object; }); | ||
}); | ||
} | ||
if (is_1.isArray(annotations)) { | ||
if (isArray(annotations)) { | ||
var _a = __read(annotations, 2), root = _a[0], other = _a[1]; | ||
root.forEach(function (identicalPath) { | ||
plain = accessDeep_1.setDeep(plain, pathstringifier_2.parsePath(identicalPath), function () { return plain; }); | ||
plain = setDeep(plain, parsePath(identicalPath), function () { return plain; }); | ||
}); | ||
if (other) { | ||
util_1.forEach(other, apply); | ||
forEach(other, apply); | ||
} | ||
} | ||
else { | ||
util_1.forEach(annotations, apply); | ||
forEach(annotations, apply); | ||
} | ||
return plain; | ||
} | ||
exports.applyReferentialEqualityAnnotations = applyReferentialEqualityAnnotations; | ||
var isDeep = function (object, superJson) { | ||
return is_1.isPlainObject(object) || | ||
is_1.isArray(object) || | ||
is_1.isMap(object) || | ||
is_1.isSet(object) || | ||
transformer_1.isInstanceOfRegisteredClass(object, superJson); | ||
return isPlainObject(object) || | ||
isArray(object) || | ||
isMap(object) || | ||
isSet(object) || | ||
isInstanceOfRegisteredClass(object, superJson); | ||
}; | ||
@@ -99,3 +94,3 @@ function addIdentity(object, path, identities) { | ||
} | ||
function generateReferentialEqualityAnnotations(identitites, dedupe) { | ||
export function generateReferentialEqualityAnnotations(identitites, dedupe) { | ||
var result = {}; | ||
@@ -117,10 +112,10 @@ var rootEqualityPaths = undefined; | ||
if (representativePath.length === 0) { | ||
rootEqualityPaths = identicalPaths.map(pathstringifier_1.stringifyPath); | ||
rootEqualityPaths = identicalPaths.map(stringifyPath); | ||
} | ||
else { | ||
result[pathstringifier_1.stringifyPath(representativePath)] = identicalPaths.map(pathstringifier_1.stringifyPath); | ||
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath); | ||
} | ||
}); | ||
if (rootEqualityPaths) { | ||
if (is_1.isEmptyObject(result)) { | ||
if (isEmptyObject(result)) { | ||
return [rootEqualityPaths]; | ||
@@ -133,7 +128,6 @@ } | ||
else { | ||
return is_1.isEmptyObject(result) ? undefined : result; | ||
return isEmptyObject(result) ? undefined : result; | ||
} | ||
} | ||
exports.generateReferentialEqualityAnnotations = generateReferentialEqualityAnnotations; | ||
var walker = function (object, identities, superJson, dedupe, path, objectsInThisPath, seenObjects) { | ||
export var walker = function (object, identities, superJson, dedupe, path, objectsInThisPath, seenObjects) { | ||
var _a; | ||
@@ -143,3 +137,3 @@ if (path === void 0) { path = []; } | ||
if (seenObjects === void 0) { seenObjects = new Map(); } | ||
var primitive = is_1.isPrimitive(object); | ||
var primitive = isPrimitive(object); | ||
if (!primitive) { | ||
@@ -158,3 +152,3 @@ addIdentity(object, path, identities); | ||
if (!isDeep(object, superJson)) { | ||
var transformed_1 = transformer_1.transformValue(object, superJson); | ||
var transformed_1 = transformValue(object, superJson); | ||
var result_1 = transformed_1 | ||
@@ -173,3 +167,3 @@ ? { | ||
} | ||
if (util_1.includes(objectsInThisPath, object)) { | ||
if (includes(objectsInThisPath, object)) { | ||
// prevent circular references | ||
@@ -180,19 +174,19 @@ return { | ||
} | ||
var transformationResult = transformer_1.transformValue(object, superJson); | ||
var transformationResult = transformValue(object, superJson); | ||
var transformed = (_a = transformationResult === null || transformationResult === void 0 ? void 0 : transformationResult.value) !== null && _a !== void 0 ? _a : object; | ||
var transformedValue = is_1.isArray(transformed) ? [] : {}; | ||
var transformedValue = isArray(transformed) ? [] : {}; | ||
var innerAnnotations = {}; | ||
util_1.forEach(transformed, function (value, index) { | ||
var recursiveResult = exports.walker(value, identities, superJson, dedupe, __spreadArray(__spreadArray([], __read(path)), [index]), __spreadArray(__spreadArray([], __read(objectsInThisPath)), [object]), seenObjects); | ||
forEach(transformed, function (value, index) { | ||
var recursiveResult = walker(value, identities, superJson, dedupe, __spreadArray(__spreadArray([], __read(path)), [index]), __spreadArray(__spreadArray([], __read(objectsInThisPath)), [object]), seenObjects); | ||
transformedValue[index] = recursiveResult.transformedValue; | ||
if (is_1.isArray(recursiveResult.annotations)) { | ||
if (isArray(recursiveResult.annotations)) { | ||
innerAnnotations[index] = recursiveResult.annotations; | ||
} | ||
else if (is_1.isPlainObject(recursiveResult.annotations)) { | ||
util_1.forEach(recursiveResult.annotations, function (tree, key) { | ||
innerAnnotations[pathstringifier_1.escapeKey(index) + '.' + key] = tree; | ||
else if (isPlainObject(recursiveResult.annotations)) { | ||
forEach(recursiveResult.annotations, function (tree, key) { | ||
innerAnnotations[escapeKey(index) + '.' + key] = tree; | ||
}); | ||
} | ||
}); | ||
var result = is_1.isEmptyObject(innerAnnotations) | ||
var result = isEmptyObject(innerAnnotations) | ||
? { | ||
@@ -215,3 +209,2 @@ transformedValue: transformedValue, | ||
}; | ||
exports.walker = walker; | ||
//# sourceMappingURL=plainer.js.map |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.Registry = void 0; | ||
var double_indexed_kv_1 = require("./double-indexed-kv"); | ||
import { DoubleIndexedKV } from './double-indexed-kv.js'; | ||
var Registry = /** @class */ (function () { | ||
function Registry(generateIdentifier) { | ||
this.generateIdentifier = generateIdentifier; | ||
this.kv = new double_indexed_kv_1.DoubleIndexedKV(); | ||
this.kv = new DoubleIndexedKV(); | ||
} | ||
@@ -30,3 +27,3 @@ Registry.prototype.register = function (value, identifier) { | ||
}()); | ||
exports.Registry = Registry; | ||
export { Registry }; | ||
//# sourceMappingURL=registry.js.map |
@@ -1,2 +0,2 @@ | ||
import SuperJSON from '.'; | ||
import SuperJSON from './index.js'; | ||
export declare type PrimitiveTypeAnnotation = 'number' | 'undefined' | 'bigint'; | ||
@@ -3,0 +3,0 @@ declare type LeafTypeAnnotation = PrimitiveTypeAnnotation | 'regexp' | 'Date' | 'Error' | 'URL'; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -34,6 +33,4 @@ __assign = Object.assign || function(t) { | ||
}; | ||
exports.__esModule = true; | ||
exports.untransformValue = exports.transformValue = exports.isInstanceOfRegisteredClass = void 0; | ||
var is_1 = require("./is"); | ||
var util_1 = require("./util"); | ||
import { isBigint, isDate, isInfinite, isMap, isNaNValue, isRegExp, isSet, isUndefined, isSymbol, isArray, isError, isTypedArray, isURL, } from './is.js'; | ||
import { findArr } from './util.js'; | ||
function simpleTransformation(isApplicable, annotation, transform, untransform) { | ||
@@ -48,4 +45,4 @@ return { | ||
var simpleRules = [ | ||
simpleTransformation(is_1.isUndefined, 'undefined', function () { return null; }, function () { return undefined; }), | ||
simpleTransformation(is_1.isBigint, 'bigint', function (v) { return v.toString(); }, function (v) { | ||
simpleTransformation(isUndefined, 'undefined', function () { return null; }, function () { return undefined; }), | ||
simpleTransformation(isBigint, 'bigint', function (v) { return v.toString(); }, function (v) { | ||
if (typeof BigInt !== 'undefined') { | ||
@@ -57,4 +54,4 @@ return BigInt(v); | ||
}), | ||
simpleTransformation(is_1.isDate, 'Date', function (v) { return v.toISOString(); }, function (v) { return new Date(v); }), | ||
simpleTransformation(is_1.isError, 'Error', function (v, superJson) { | ||
simpleTransformation(isDate, 'Date', function (v) { return v.toISOString(); }, function (v) { return new Date(v); }), | ||
simpleTransformation(isError, 'Error', function (v, superJson) { | ||
var baseError = { | ||
@@ -77,3 +74,3 @@ name: v.name, | ||
}), | ||
simpleTransformation(is_1.isRegExp, 'regexp', function (v) { return '' + v; }, function (regex) { | ||
simpleTransformation(isRegExp, 'regexp', function (v) { return '' + v; }, function (regex) { | ||
var body = regex.slice(1, regex.lastIndexOf('/')); | ||
@@ -83,9 +80,9 @@ var flags = regex.slice(regex.lastIndexOf('/') + 1); | ||
}), | ||
simpleTransformation(is_1.isSet, 'set', | ||
simpleTransformation(isSet, 'set', | ||
// (sets only exist in es6+) | ||
// eslint-disable-next-line es5/no-es6-methods | ||
function (v) { return __spreadArray([], __read(v.values())); }, function (v) { return new Set(v); }), | ||
simpleTransformation(is_1.isMap, 'map', function (v) { return __spreadArray([], __read(v.entries())); }, function (v) { return new Map(v); }), | ||
simpleTransformation(function (v) { return is_1.isNaNValue(v) || is_1.isInfinite(v); }, 'number', function (v) { | ||
if (is_1.isNaNValue(v)) { | ||
simpleTransformation(isMap, 'map', function (v) { return __spreadArray([], __read(v.entries())); }, function (v) { return new Map(v); }), | ||
simpleTransformation(function (v) { return isNaNValue(v) || isInfinite(v); }, 'number', function (v) { | ||
if (isNaNValue(v)) { | ||
return 'NaN'; | ||
@@ -103,3 +100,3 @@ } | ||
}, Number), | ||
simpleTransformation(is_1.isURL, 'URL', function (v) { return v.toString(); }, function (v) { return new URL(v); }), | ||
simpleTransformation(isURL, 'URL', function (v) { return v.toString(); }, function (v) { return new URL(v); }), | ||
]; | ||
@@ -115,3 +112,3 @@ function compositeTransformation(isApplicable, annotation, transform, untransform) { | ||
var symbolRule = compositeTransformation(function (s, superJson) { | ||
if (is_1.isSymbol(s)) { | ||
if (isSymbol(s)) { | ||
var isRegistered = !!superJson.symbolRegistry.getIdentifier(s); | ||
@@ -145,3 +142,3 @@ return isRegistered; | ||
}, {}); | ||
var typedArrayRule = compositeTransformation(is_1.isTypedArray, function (v) { return ['typed-array', v.constructor.name]; }, function (v) { return __spreadArray([], __read(v)); }, function (v, a) { | ||
var typedArrayRule = compositeTransformation(isTypedArray, function (v) { return ['typed-array', v.constructor.name]; }, function (v) { return __spreadArray([], __read(v)); }, function (v, a) { | ||
var ctor = constructorToName[a[1]]; | ||
@@ -153,3 +150,3 @@ if (!ctor) { | ||
}); | ||
function isInstanceOfRegisteredClass(potentialClass, superJson) { | ||
export function isInstanceOfRegisteredClass(potentialClass, superJson) { | ||
if (potentialClass === null || potentialClass === void 0 ? void 0 : potentialClass.constructor) { | ||
@@ -161,3 +158,2 @@ var isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor); | ||
} | ||
exports.isInstanceOfRegisteredClass = isInstanceOfRegisteredClass; | ||
var classRule = compositeTransformation(isInstanceOfRegisteredClass, function (clazz, superJson) { | ||
@@ -199,4 +195,4 @@ var identifier = superJson.classRegistry.getIdentifier(clazz.constructor); | ||
var compositeRules = [classRule, symbolRule, customRule, typedArrayRule]; | ||
var transformValue = function (value, superJson) { | ||
var applicableCompositeRule = util_1.findArr(compositeRules, function (rule) { | ||
export var transformValue = function (value, superJson) { | ||
var applicableCompositeRule = findArr(compositeRules, function (rule) { | ||
return rule.isApplicable(value, superJson); | ||
@@ -210,3 +206,3 @@ }); | ||
} | ||
var applicableSimpleRule = util_1.findArr(simpleRules, function (rule) { | ||
var applicableSimpleRule = findArr(simpleRules, function (rule) { | ||
return rule.isApplicable(value, superJson); | ||
@@ -222,3 +218,2 @@ }); | ||
}; | ||
exports.transformValue = transformValue; | ||
var simpleRulesByAnnotation = {}; | ||
@@ -228,4 +223,4 @@ simpleRules.forEach(function (rule) { | ||
}); | ||
var untransformValue = function (json, type, superJson) { | ||
if (is_1.isArray(type)) { | ||
export var untransformValue = function (json, type, superJson) { | ||
if (isArray(type)) { | ||
switch (type[0]) { | ||
@@ -252,3 +247,2 @@ case 'symbol': | ||
}; | ||
exports.untransformValue = untransformValue; | ||
//# sourceMappingURL=transformer.js.map |
@@ -1,3 +0,3 @@ | ||
import { TypeAnnotation } from './transformer'; | ||
import { MinimisedTree, ReferentialEqualityAnnotations } from './plainer'; | ||
import { TypeAnnotation } from './transformer.js'; | ||
import { MinimisedTree, ReferentialEqualityAnnotations } from './plainer.js'; | ||
export declare type Class = { | ||
@@ -4,0 +4,0 @@ new (...args: any[]): any; |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
@@ -18,4 +17,2 @@ var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
}; | ||
exports.__esModule = true; | ||
exports.findArr = exports.includes = exports.forEach = exports.find = void 0; | ||
function valuesOfObj(record) { | ||
@@ -35,3 +32,3 @@ if ('values' in Object) { | ||
} | ||
function find(record, predicate) { | ||
export function find(record, predicate) { | ||
var values = valuesOfObj(record); | ||
@@ -51,4 +48,3 @@ if ('find' in values) { | ||
} | ||
exports.find = find; | ||
function forEach(record, run) { | ||
export function forEach(record, run) { | ||
Object.entries(record).forEach(function (_a) { | ||
@@ -59,8 +55,6 @@ var _b = __read(_a, 2), key = _b[0], value = _b[1]; | ||
} | ||
exports.forEach = forEach; | ||
function includes(arr, value) { | ||
export function includes(arr, value) { | ||
return arr.indexOf(value) !== -1; | ||
} | ||
exports.includes = includes; | ||
function findArr(record, predicate) { | ||
export function findArr(record, predicate) { | ||
for (var i = 0; i < record.length; i++) { | ||
@@ -74,3 +68,2 @@ var value = record[i]; | ||
} | ||
exports.findArr = findArr; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"version": "1.13.3", | ||
"version": "1.13.4-0", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"typings": "dist/index.d.ts", | ||
"module": "dist/esm/index.js", | ||
"exports": { | ||
".": "./dist/index.js" | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=16" | ||
}, | ||
"scripts": { | ||
"build": "yarn build:cjs && yarn build:esm", | ||
"build:cjs": "tsc", | ||
"build:esm": "tsc --module es2015 --outDir dist/esm", | ||
"test": "tsdx test --notify --verbose", | ||
"build": "tsc", | ||
"test": "vitest run", | ||
"lint": "tsdx lint", | ||
"prepack": "yarn build", | ||
"prepare": "husky install", | ||
"publish-please": "publish-please", | ||
"prepublishOnly": "publish-please guard" | ||
"prepare": "husky install" | ||
}, | ||
@@ -69,3 +66,4 @@ "importSort": { | ||
"tsdx": "^0.14.1", | ||
"typescript": "^4.2.4" | ||
"typescript": "^4.2.4", | ||
"vitest": "^0.34.6" | ||
}, | ||
@@ -77,6 +75,4 @@ "dependencies": { | ||
"**/@typescript-eslint/eslint-plugin": "^4.11.1", | ||
"**/@typescript-eslint/parser": "^4.11.1", | ||
"**/jest": "^26.6.3", | ||
"**/ts-jest": "^26.4.4" | ||
"**/@typescript-eslint/parser": "^4.11.1" | ||
} | ||
} |
<p align="center"> | ||
<img alt="superjson" src="./docs/superjson.png" width="300" /> | ||
<img alt="superjson" src="./docs/superjson-banner.png" width="800" /> | ||
</p> | ||
@@ -46,5 +46,9 @@ | ||
## Sponsors | ||
[<img src="https://raw.githubusercontent.com/blitz-js/blitz/main/assets/flightcontrol.png" alt="Flightcontrol Logo" style="width: 400px;"/>](https://www.flightcontrol.dev/?ref=superjson) | ||
Superjson logo by [NUMI](https://github.com/numi-hq/open-design): | ||
[<img src="https://raw.githubusercontent.com/numi-hq/open-design/main/assets/numi-lockup.png" alt="NUMI Logo" style="width: 200px;"/>](https://numi.tech/?ref=superjson) | ||
## Getting started | ||
@@ -75,3 +79,3 @@ | ||
```js | ||
const object = superjson.parse<{ date: Date }>(jsonString); | ||
const object = superjson.parse < { date: Date } > jsonString; | ||
@@ -125,2 +129,3 @@ // object === { date: new Date(0) } | ||
To use the [SuperJSON SWC plugin](https://github.com/blitz-js/next-superjson-plugin), install it and add it to your `next.config.js`: | ||
```sh | ||
@@ -130,3 +135,2 @@ yarn add next-superjson-plugin | ||
```js | ||
@@ -145,6 +149,7 @@ // next.config.js | ||
}, | ||
} | ||
}; | ||
``` | ||
### Next.js (stable Babel transform) | ||
Install the library with your package manager of choice, e.g.: | ||
@@ -242,16 +247,16 @@ | ||
| ----------- | --------------------------- | ----------------------- | | ||
| `string` | β | β | | ||
| `number` | β | β | | ||
| `boolean` | β | β | | ||
| `null` | β | β | | ||
| `Array` | β | β | | ||
| `Object` | β | β | | ||
| `undefined` | β | β | | ||
| `bigint` | β | β | | ||
| `Date` | β | β | | ||
| `RegExp` | β | β | | ||
| `Set` | β | β | | ||
| `Map` | β | β | | ||
| `Error` | β | β | | ||
| `URL` | β | β | | ||
| `string` | β | β | | ||
| `number` | β | β | | ||
| `boolean` | β | β | | ||
| `null` | β | β | | ||
| `Array` | β | β | | ||
| `Object` | β | β | | ||
| `undefined` | β | β | | ||
| `bigint` | β | β | | ||
| `Date` | β | β | | ||
| `RegExp` | β | β | | ||
| `Set` | β | β | | ||
| `Map` | β | β | | ||
| `Error` | β | β | | ||
| `URL` | β | β | | ||
@@ -269,3 +274,3 @@ ## Recipes | ||
```ts | ||
import { Decimal }Β from "decimal.js" | ||
import { Decimal } from 'decimal.js'; | ||
@@ -282,4 +287,2 @@ SuperJSON.registerCustom<Decimal, string>( | ||
## Contributors β¨ | ||
@@ -286,0 +289,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
342
Yes
96593
12
39
1126
2