compress-json
Advanced tools
Comparing version 0.2.0 to 1.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.test = exports.bool_to_s = exports.s_to_bool = void 0; | ||
function s_to_bool(s) { | ||
@@ -4,0 +5,0 @@ switch (s) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.config = void 0; | ||
exports.config = { | ||
sort_key: false, | ||
}; |
@@ -5,2 +5,3 @@ import { Key, Value } from './memory'; | ||
export declare function compress(o: object): Compressed; | ||
export declare function decode(values: Values, key: Key): any; | ||
export declare function decompress(c: Compressed): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decompress = exports.decode = exports.compress = void 0; | ||
const debug_1 = require("./debug"); | ||
@@ -75,2 +76,3 @@ const encode_1 = require("./encode"); | ||
} | ||
exports.decode = decode; | ||
function decompress(c) { | ||
@@ -77,0 +79,0 @@ const [values, root] = c; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.throwUnknownDataType = exports.getType = void 0; | ||
function getType(o) { | ||
@@ -4,0 +5,0 @@ return Object.prototype.toString.call(o); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeStr = exports.encodeStr = exports.decodeBool = exports.encodeBool = exports.decodeKey = exports.decodeNum = exports.encodeNum = void 0; | ||
const number_1 = require("./number"); | ||
@@ -4,0 +5,0 @@ function encodeNum(num) { |
export { compress, decompress, Compressed } from './core'; | ||
export { decode } from './core'; | ||
export { addValue, Memory, Store, Cache } from './memory'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* for direct usage */ | ||
var core_1 = require("./core"); | ||
exports.compress = core_1.compress; | ||
exports.decompress = core_1.decompress; | ||
Object.defineProperty(exports, "compress", { enumerable: true, get: function () { return core_1.compress; } }); | ||
Object.defineProperty(exports, "decompress", { enumerable: true, get: function () { return core_1.decompress; } }); | ||
/* for custom wrapper */ | ||
var core_2 = require("./core"); | ||
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return core_2.decode; } }); | ||
var memory_1 = require("./memory"); | ||
Object.defineProperty(exports, "addValue", { enumerable: true, get: function () { return memory_1.addValue; } }); |
@@ -14,2 +14,16 @@ declare type Parent = any[] | object; | ||
export interface Store { | ||
add(value: Value): void; | ||
forEach(cb: (value: Value) => void | 'break'): void; | ||
toArray(): Value[]; | ||
} | ||
/** | ||
* potential implementation of cache are: | ||
* - raw object ({}) | ||
* - array | ||
* - Map | ||
* - localStorage | ||
* - lmdb | ||
* - leveldb (sync mode) | ||
* */ | ||
export interface Cache { | ||
has(key: Key): boolean; | ||
@@ -22,9 +36,10 @@ get(key: Key): Value | undefined; | ||
store: Store; | ||
cache: Store; | ||
cache: Cache; | ||
keyCount: number; | ||
} | ||
export declare function memToValues(mem: Memory): any[]; | ||
export declare function memToValues(mem: Memory): Value[]; | ||
export declare function makeInMemoryStore(): Store; | ||
export declare function makeInMemoryCache(): Cache; | ||
export declare function makeInMemoryMemory(): Memory; | ||
export declare function addValue(mem: Memory, o: any, parent: Parent | undefined): Key; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addValue = exports.makeInMemoryMemory = exports.makeInMemoryCache = exports.makeInMemoryStore = exports.memToValues = void 0; | ||
const config_1 = require("./config"); | ||
@@ -8,12 +9,25 @@ const debug_1 = require("./debug"); | ||
function memToValues(mem) { | ||
const n = mem.keyCount; | ||
const vs = new Array(n); | ||
for (let i = 0; i < n; i++) { | ||
const v = mem.store.get(i.toString()); | ||
vs[i] = v; | ||
} | ||
return vs; | ||
return mem.store.toArray(); | ||
} | ||
exports.memToValues = memToValues; | ||
function makeInMemoryStore() { | ||
const mem = []; | ||
return { | ||
forEach(cb) { | ||
for (let i = 0; i < mem.length; i++) { | ||
if (cb(mem[i]) === 'break') { | ||
return; | ||
} | ||
} | ||
}, | ||
add(value) { | ||
mem.push(value); | ||
}, | ||
toArray() { | ||
return mem; | ||
}, | ||
}; | ||
} | ||
exports.makeInMemoryStore = makeInMemoryStore; | ||
function makeInMemoryCache() { | ||
const mem = {}; | ||
@@ -39,7 +53,7 @@ return { | ||
} | ||
exports.makeInMemoryStore = makeInMemoryStore; | ||
exports.makeInMemoryCache = makeInMemoryCache; | ||
function makeInMemoryMemory() { | ||
return { | ||
store: makeInMemoryStore(), | ||
cache: makeInMemoryStore(), | ||
cache: makeInMemoryCache(), | ||
keyCount: 0, | ||
@@ -55,3 +69,3 @@ }; | ||
const key = number_1.num_to_s(id); | ||
mem.store.set(id.toString(), value); | ||
mem.store.add(value); | ||
mem.cache.set(value, key); | ||
@@ -58,0 +72,0 @@ return key; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.s_to_num = exports.num_to_s = exports.int_to_s = exports.s_to_int = void 0; | ||
let i_to_s = ''; | ||
@@ -54,2 +55,5 @@ for (let i = 0; i < 10; i++) { | ||
function num_to_s(num) { | ||
if (num < 0) { | ||
return '-' + num_to_s(-num); | ||
} | ||
let [a, b] = num.toString().split('.'); | ||
@@ -66,2 +70,5 @@ if (!b) { | ||
function s_to_num(s) { | ||
if (s[0] === '-') { | ||
return -s_to_num(s.substr(1)); | ||
} | ||
let [a, b] = s.split('.'); | ||
@@ -68,0 +75,0 @@ if (!b) { |
{ | ||
"name": "compress-json", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "convert JSON data to space efficient format", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19844
474
1