jsonschema-key-compression
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -11,8 +11,9 @@ "use strict"; | ||
exports.DEFAULT_COMPRESSION_FLAG = '|'; | ||
function createCompressionTable(schema, compressionFlag) { | ||
function createCompressionTable(schema, compressionFlag, ignoreProperties) { | ||
if (compressionFlag === void 0) { compressionFlag = exports.DEFAULT_COMPRESSION_FLAG; } | ||
var table = _compressedToUncompressedTable(schema); | ||
if (ignoreProperties === void 0) { ignoreProperties = []; } | ||
var table = compressedToUncompressedTable(schema, ignoreProperties); | ||
var compressionTable = { | ||
compressedToUncompressed: table, | ||
uncompressedToCompressed: uncompressedToCompressedTable(table, compressionFlag), | ||
uncompressedToCompressed: uncompressedToCompressedTable(table, compressionFlag, ignoreProperties), | ||
compressionFlag: compressionFlag | ||
@@ -51,3 +52,3 @@ }; | ||
exports.getPropertiesOfSchema = getPropertiesOfSchema; | ||
function _compressedToUncompressedTable(schema) { | ||
function compressedToUncompressedTable(schema, ignoreProperties) { | ||
var attributes = getPropertiesOfSchema(schema); | ||
@@ -58,3 +59,3 @@ var schemaKeysSorted = Array.from(attributes).sort(util_1.alphabeticCompare); | ||
schemaKeysSorted | ||
.filter(function (k) { return k.length > 3; }) | ||
.filter(function (k) { return k.length > 3 && !ignoreProperties.includes(k); }) | ||
.forEach(function (k) { | ||
@@ -67,8 +68,10 @@ var compressKey = util_1.numberToLetter(lastKeyNumber); | ||
} | ||
exports._compressedToUncompressedTable = _compressedToUncompressedTable; | ||
function uncompressedToCompressedTable(table, compressionFlag) { | ||
exports.compressedToUncompressedTable = compressedToUncompressedTable; | ||
function uncompressedToCompressedTable(table, compressionFlag, ignoreProperties) { | ||
var reverseTable = new Map(); | ||
Array.from(table.keys()).forEach(function (key) { | ||
var value = table.get(key); | ||
reverseTable.set(compressionFlag + value, key); | ||
if (!ignoreProperties.includes(value)) { | ||
reverseTable.set(compressionFlag + value, key); | ||
} | ||
}); | ||
@@ -75,0 +78,0 @@ return reverseTable; |
@@ -9,7 +9,7 @@ import { numberToLetter, alphabeticCompare } from './util'; | ||
export const DEFAULT_COMPRESSION_FLAG = '|'; | ||
export function createCompressionTable(schema, compressionFlag = DEFAULT_COMPRESSION_FLAG) { | ||
const table = _compressedToUncompressedTable(schema); | ||
export function createCompressionTable(schema, compressionFlag = DEFAULT_COMPRESSION_FLAG, ignoreProperties = []) { | ||
const table = compressedToUncompressedTable(schema, ignoreProperties); | ||
const compressionTable = { | ||
compressedToUncompressed: table, | ||
uncompressedToCompressed: uncompressedToCompressedTable(table, compressionFlag), | ||
uncompressedToCompressed: uncompressedToCompressedTable(table, compressionFlag, ignoreProperties), | ||
compressionFlag | ||
@@ -46,3 +46,3 @@ }; | ||
} | ||
export function _compressedToUncompressedTable(schema) { | ||
export function compressedToUncompressedTable(schema, ignoreProperties) { | ||
const attributes = getPropertiesOfSchema(schema); | ||
@@ -53,3 +53,3 @@ const schemaKeysSorted = Array.from(attributes).sort(alphabeticCompare); | ||
schemaKeysSorted | ||
.filter(k => k.length > 3) | ||
.filter(k => k.length > 3 && !ignoreProperties.includes(k)) | ||
.forEach(k => { | ||
@@ -62,7 +62,9 @@ const compressKey = numberToLetter(lastKeyNumber); | ||
} | ||
export function uncompressedToCompressedTable(table, compressionFlag) { | ||
export function uncompressedToCompressedTable(table, compressionFlag, ignoreProperties) { | ||
const reverseTable = new Map(); | ||
Array.from(table.keys()).forEach(key => { | ||
const value = table.get(key); | ||
reverseTable.set(compressionFlag + value, key); | ||
if (!ignoreProperties.includes(value)) { | ||
reverseTable.set(compressionFlag + value, key); | ||
} | ||
}); | ||
@@ -69,0 +71,0 @@ return reverseTable; |
{ | ||
"name": "jsonschema-key-compression", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Compress json-data based on it's json-schema", | ||
@@ -5,0 +5,0 @@ "author": "pubkey", |
import { | ||
PlainJsonObject, | ||
CompressionTable, | ||
@@ -22,5 +21,9 @@ JsonSchema, | ||
schema: JsonSchema, | ||
compressionFlag: string = DEFAULT_COMPRESSION_FLAG | ||
compressionFlag: string = DEFAULT_COMPRESSION_FLAG, | ||
ignoreProperties: string[] = [] | ||
): CompressionTable { | ||
const table = _compressedToUncompressedTable(schema); | ||
const table = compressedToUncompressedTable( | ||
schema, | ||
ignoreProperties | ||
); | ||
const compressionTable: CompressionTable = { | ||
@@ -30,3 +33,4 @@ compressedToUncompressed: table, | ||
table, | ||
compressionFlag | ||
compressionFlag, | ||
ignoreProperties | ||
), | ||
@@ -69,3 +73,6 @@ compressionFlag | ||
export function _compressedToUncompressedTable(schema: JsonSchema): TableType { | ||
export function compressedToUncompressedTable( | ||
schema: JsonSchema, | ||
ignoreProperties: string[] | ||
): TableType { | ||
const attributes: Set<string> = getPropertiesOfSchema(schema); | ||
@@ -76,3 +83,3 @@ const schemaKeysSorted: string[] = Array.from(attributes).sort(alphabeticCompare); | ||
schemaKeysSorted | ||
.filter(k => k.length > 3) | ||
.filter(k => k.length > 3 && !ignoreProperties.includes(k)) | ||
.forEach(k => { | ||
@@ -88,3 +95,4 @@ const compressKey = numberToLetter(lastKeyNumber); | ||
table: TableType, | ||
compressionFlag: string | ||
compressionFlag: string, | ||
ignoreProperties: string[] | ||
): TableType { | ||
@@ -94,5 +102,7 @@ const reverseTable: TableType = new Map(); | ||
const value = table.get(key) as string; | ||
reverseTable.set(compressionFlag + value, key); | ||
if (!ignoreProperties.includes(value)) { | ||
reverseTable.set(compressionFlag + value, key); | ||
} | ||
}); | ||
return reverseTable; | ||
} |
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
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
71575
1102