@ts-common/source-map
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -29,5 +29,7 @@ import { StringMap } from "@ts-common/string-map"; | ||
export declare type Tracked<T extends object> = T & TrackedBase; | ||
export declare const setInfoFunc: <T extends object>(value: T, infoFunc: () => ObjectInfo) => Tracked<T>; | ||
export declare const setInfo: <T extends object>(value: T, info: ObjectInfo) => Tracked<T>; | ||
export declare const getInfoFunc: (value: object) => (() => ObjectInfo) | undefined; | ||
export declare const getInfo: (value: object) => RootObjectInfo | ChildObjectInfo | undefined; | ||
export declare const copyInfo: <T extends object>(source: object, dest: T) => T; | ||
export declare const getInfo: (value: object) => RootObjectInfo | ChildObjectInfo | undefined; | ||
export declare type Data = object | JsonPrimitive; | ||
@@ -34,0 +36,0 @@ export declare const copyDataInfo: <T extends Data>(source: Data, dest: T) => T; |
22
index.js
@@ -19,21 +19,25 @@ "use strict"; | ||
exports.objectInfoSymbol = Symbol.for("@ts-common/source-map/object-info"); | ||
exports.setInfo = (value, info) => { | ||
exports.setInfoFunc = (value, infoFunc) => { | ||
const result = value; | ||
if (result[exports.objectInfoSymbol] === undefined) { | ||
result[exports.objectInfoSymbol] = () => info; | ||
result[exports.objectInfoSymbol] = infoFunc; | ||
} | ||
return result; | ||
}; | ||
exports.setInfo = (value, info) => exports.setInfoFunc(value, () => info); | ||
exports.getInfoFunc = (value) => { | ||
const withInfo = value; | ||
return withInfo[exports.objectInfoSymbol]; | ||
}; | ||
exports.getInfo = (value) => { | ||
const f = exports.getInfoFunc(value); | ||
return f === undefined ? undefined : f(); | ||
}; | ||
exports.copyInfo = (source, dest) => { | ||
const info = exports.getInfo(source); | ||
const info = exports.getInfoFunc(source); | ||
if (info !== undefined) { | ||
exports.setInfo(dest, info); | ||
exports.setInfoFunc(dest, info); | ||
} | ||
return dest; | ||
}; | ||
exports.getInfo = (value) => { | ||
const withInfo = value; | ||
const f = withInfo[exports.objectInfoSymbol]; | ||
return f === undefined ? undefined : f(); | ||
}; | ||
exports.copyDataInfo = (source, dest) => { | ||
@@ -40,0 +44,0 @@ const destJson = dest; |
{ | ||
"name": "@ts-common/source-map", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Source Map", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
19960
165