@blurpaper/shared 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/key-alphabet.class.d.ts +11 -0
- package/dist/classes/key-alphabet.class.js +57 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +11 -0
- package/dist/helpers/object.helper.d.ts +5 -0
- package/dist/helpers/object.helper.js +38 -0
- package/dist/helpers/string.helper.d.ts +2 -0
- package/dist/helpers/string.helper.js +44 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/interfaces/alphabet-settings-input.interface.d.ts +6 -0
- package/dist/interfaces/alphabet-settings-input.interface.js +2 -0
- package/dist/interfaces/start-end.interface.d.ts +6 -0
- package/dist/interfaces/start-end.interface.js +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IAlphabetSettingsInput } from "../interfaces/alphabet-settings-input.interface";
|
|
2
|
+
export declare class KeyAlphabet {
|
|
3
|
+
private keyAlphabetMap;
|
|
4
|
+
private alphabetKeyMap;
|
|
5
|
+
private lastGeneratedAlphabetMap;
|
|
6
|
+
getKeyAlphabetMap(session?: string): Record<string, string>;
|
|
7
|
+
getAlphabetKeyMap(session?: string): Record<string, string>;
|
|
8
|
+
addToAlphabet(key: string, session?: string, settings?: IAlphabetSettingsInput): string;
|
|
9
|
+
nextKey(key?: string): string;
|
|
10
|
+
formatGeneratedAlphabet(alphabet: string, settings?: IAlphabetSettingsInput): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyAlphabet = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
class KeyAlphabet {
|
|
6
|
+
keyAlphabetMap = {};
|
|
7
|
+
alphabetKeyMap = {};
|
|
8
|
+
lastGeneratedAlphabetMap = {};
|
|
9
|
+
getKeyAlphabetMap(session = constants_1.ALPHABET_DEFAULT_SESSION) {
|
|
10
|
+
return this.keyAlphabetMap[session];
|
|
11
|
+
}
|
|
12
|
+
getAlphabetKeyMap(session = constants_1.ALPHABET_DEFAULT_SESSION) {
|
|
13
|
+
return this.alphabetKeyMap[session];
|
|
14
|
+
}
|
|
15
|
+
addToAlphabet(key, session = constants_1.ALPHABET_DEFAULT_SESSION, settings) {
|
|
16
|
+
if (!this.keyAlphabetMap[session]) {
|
|
17
|
+
this.keyAlphabetMap[session] = {};
|
|
18
|
+
}
|
|
19
|
+
if (!this.alphabetKeyMap[session]) {
|
|
20
|
+
this.alphabetKeyMap[session] = {};
|
|
21
|
+
}
|
|
22
|
+
if (this.keyAlphabetMap[session][key]) {
|
|
23
|
+
return this.keyAlphabetMap[session][key];
|
|
24
|
+
}
|
|
25
|
+
if (!this.lastGeneratedAlphabetMap[session]) {
|
|
26
|
+
this.lastGeneratedAlphabetMap[session] = '';
|
|
27
|
+
}
|
|
28
|
+
if ((!settings || settings.noLowerKeys) && (this.lastGeneratedAlphabetMap[session].length >= key.length)) {
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
this.lastGeneratedAlphabetMap[session] = this.nextKey(this.lastGeneratedAlphabetMap[session]);
|
|
32
|
+
const generatedAlphabet = this.formatGeneratedAlphabet(this.lastGeneratedAlphabetMap[session], settings);
|
|
33
|
+
this.alphabetKeyMap[session][generatedAlphabet] = key;
|
|
34
|
+
if (!settings || settings.addKeyAlphabet) {
|
|
35
|
+
this.keyAlphabetMap[session][key] = generatedAlphabet;
|
|
36
|
+
}
|
|
37
|
+
return generatedAlphabet;
|
|
38
|
+
}
|
|
39
|
+
nextKey(key = constants_1.FIRST_ALPHABET) {
|
|
40
|
+
let chars = key.split('');
|
|
41
|
+
let i = chars.length - 1;
|
|
42
|
+
while (i >= 0) {
|
|
43
|
+
let index = constants_1.ALPHABET.indexOf(chars[i]);
|
|
44
|
+
if (index < constants_1.ALPHABET.length - 1) {
|
|
45
|
+
chars[i] = constants_1.ALPHABET[index + 1];
|
|
46
|
+
return chars.join('');
|
|
47
|
+
}
|
|
48
|
+
chars[i] = constants_1.FIRST_ALPHABET;
|
|
49
|
+
i -= 1;
|
|
50
|
+
}
|
|
51
|
+
return constants_1.FIRST_ALPHABET + chars.join('');
|
|
52
|
+
}
|
|
53
|
+
formatGeneratedAlphabet(alphabet, settings) {
|
|
54
|
+
return `${settings && settings.preffix || ''}${alphabet}${settings && settings.suffix || ''}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.KeyAlphabet = KeyAlphabet;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const ALPHABET: string;
|
|
2
|
+
export declare const NUMERIC_ALPHABET: string[];
|
|
3
|
+
export declare const FIRST_ALPHABET: string;
|
|
4
|
+
export declare const ALPHABET_DEFAULT_SESSION: string;
|
|
5
|
+
export declare const GUID_REGEX: RegExp;
|
|
6
|
+
export declare const NUMBER_REGEX: RegExp;
|
|
7
|
+
export declare const VISITED_SESSION_GENERATION_KEY: string;
|
|
8
|
+
export declare const LARGE_REPETITABLE_KEY: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LARGE_REPETITABLE_KEY = exports.VISITED_SESSION_GENERATION_KEY = exports.NUMBER_REGEX = exports.GUID_REGEX = exports.ALPHABET_DEFAULT_SESSION = exports.FIRST_ALPHABET = exports.NUMERIC_ALPHABET = exports.ALPHABET = void 0;
|
|
4
|
+
exports.ALPHABET = 'abcdefghijklmnopqrstuvwxyz';
|
|
5
|
+
exports.NUMERIC_ALPHABET = exports.ALPHABET.split('');
|
|
6
|
+
exports.FIRST_ALPHABET = exports.NUMERIC_ALPHABET[0];
|
|
7
|
+
exports.ALPHABET_DEFAULT_SESSION = 'default';
|
|
8
|
+
exports.GUID_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+){2,}$/;
|
|
9
|
+
exports.NUMBER_REGEX = /\d/;
|
|
10
|
+
exports.VISITED_SESSION_GENERATION_KEY = 'visitedBlurPaperGeneratedObjectCurrentSession';
|
|
11
|
+
exports.LARGE_REPETITABLE_KEY = 'list';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { KeyAlphabet } from "../classes/key-alphabet.class";
|
|
2
|
+
export declare const isPrimitive: (value: any) => boolean;
|
|
3
|
+
export declare const recursivelyReassignKeysAndValues: (alphabetKeyMap: KeyAlphabet, originalObject: any | undefined, minifiedObject: any | undefined, largeRepetitables: string[] | undefined, visitingSesion: string) => void;
|
|
4
|
+
export declare const repetitableIndex: (allLargeRepetitables: string[], currentLargeRepetitable: string) => number;
|
|
5
|
+
export declare const getMinifiedObject: (alphabetKeyMap: KeyAlphabet, originalObject: any | undefined, largeRepetitables: string[] | undefined, visitingSesion: string) => any;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMinifiedObject = exports.repetitableIndex = exports.recursivelyReassignKeysAndValues = exports.isPrimitive = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const isPrimitive = (value) => (value === null) || (typeof value !== "object");
|
|
6
|
+
exports.isPrimitive = isPrimitive;
|
|
7
|
+
const recursivelyReassignKeysAndValues = (alphabetKeyMap, originalObject = {}, minifiedObject = {}, largeRepetitables = [], visitingSesion) => {
|
|
8
|
+
const keys = Object.keys(originalObject);
|
|
9
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
10
|
+
const key = keys[i];
|
|
11
|
+
if ((key === constants_1.VISITED_SESSION_GENERATION_KEY) || !key) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const isLargeRepetitable = key === constants_1.LARGE_REPETITABLE_KEY;
|
|
15
|
+
const nestedObject = originalObject[key];
|
|
16
|
+
let largeRepetitableIndex = null;
|
|
17
|
+
if (isLargeRepetitable) {
|
|
18
|
+
const stringifiedLarge = JSON.stringify(nestedObject);
|
|
19
|
+
const currentLargeRepetitableIndex = (0, exports.repetitableIndex)(largeRepetitables, stringifiedLarge);
|
|
20
|
+
largeRepetitableIndex = (currentLargeRepetitableIndex >= 0) ? currentLargeRepetitableIndex : largeRepetitables.push(stringifiedLarge) - 1;
|
|
21
|
+
}
|
|
22
|
+
const alphabetKey = alphabetKeyMap.addToAlphabet(key, undefined, { noLowerKeys: true, addKeyAlphabet: true });
|
|
23
|
+
minifiedObject[alphabetKey] = isLargeRepetitable ? largeRepetitableIndex : (0, exports.isPrimitive)(nestedObject) ? (((key === 'value') && ((typeof nestedObject === 'string'))) || (typeof nestedObject === 'number') || !isNaN(Number(nestedObject)) || (typeof nestedObject === 'boolean') || constants_1.GUID_REGEX.test(nestedObject) || constants_1.NUMBER_REGEX.test(nestedObject) || (nestedObject === undefined) || (nestedObject === null) ? nestedObject : alphabetKeyMap.addToAlphabet(nestedObject, undefined, { noLowerKeys: true, addKeyAlphabet: true })) : {};
|
|
24
|
+
if (!(0, exports.isPrimitive)(nestedObject) && !isLargeRepetitable && (!nestedObject[constants_1.VISITED_SESSION_GENERATION_KEY] || (nestedObject[constants_1.VISITED_SESSION_GENERATION_KEY] !== visitingSesion))) {
|
|
25
|
+
(0, exports.recursivelyReassignKeysAndValues)(alphabetKeyMap, nestedObject, minifiedObject[alphabetKey], largeRepetitables, visitingSesion);
|
|
26
|
+
nestedObject[constants_1.VISITED_SESSION_GENERATION_KEY] = visitingSesion;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.recursivelyReassignKeysAndValues = recursivelyReassignKeysAndValues;
|
|
31
|
+
const repetitableIndex = (allLargeRepetitables, currentLargeRepetitable) => allLargeRepetitables.findIndex((value) => value === currentLargeRepetitable);
|
|
32
|
+
exports.repetitableIndex = repetitableIndex;
|
|
33
|
+
const getMinifiedObject = (alphabetKeyMap, originalObject = {}, largeRepetitables = [], visitingSesion) => {
|
|
34
|
+
const minifiedObject = {};
|
|
35
|
+
(0, exports.recursivelyReassignKeysAndValues)(alphabetKeyMap, originalObject, minifiedObject, largeRepetitables, visitingSesion);
|
|
36
|
+
return minifiedObject;
|
|
37
|
+
};
|
|
38
|
+
exports.getMinifiedObject = getMinifiedObject;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findCommonSubstrings = void 0;
|
|
4
|
+
const findCommonSubstrings = (input1, input2, minLen = 30) => {
|
|
5
|
+
const n1 = input1.length;
|
|
6
|
+
const n2 = input2.length;
|
|
7
|
+
const dpTable = Array.from({ length: n1 + 1 }, () => Array(n2 + 1).fill(0));
|
|
8
|
+
const matchResults = {};
|
|
9
|
+
for (let i = 1; i <= n1; i++) {
|
|
10
|
+
for (let j = 1; j <= n2; j++) {
|
|
11
|
+
if (input1[i - 1] === input2[j - 1]) {
|
|
12
|
+
dpTable[i][j] = dpTable[i - 1][j - 1] + 1;
|
|
13
|
+
if (dpTable[i][j] >= minLen) {
|
|
14
|
+
const substring = input1.slice(i - dpTable[i][j], i);
|
|
15
|
+
if (!matchResults[substring]) {
|
|
16
|
+
matchResults[substring] = [];
|
|
17
|
+
}
|
|
18
|
+
matchResults[substring].push({
|
|
19
|
+
start1: i - dpTable[i][j],
|
|
20
|
+
end1: i - 1,
|
|
21
|
+
start2: j - dpTable[i][j],
|
|
22
|
+
end2: j - 1
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const sortSubsLongestFirst = Object.keys(matchResults).sort((a, b) => b.length - a.length);
|
|
29
|
+
const finalResultWithOnlyMaximalLengthStrings = {};
|
|
30
|
+
for (const currentSubstring of sortSubsLongestFirst) {
|
|
31
|
+
let isSubsctringAlreadyContainedInABiggerString = false;
|
|
32
|
+
for (const existingString in finalResultWithOnlyMaximalLengthStrings) {
|
|
33
|
+
if (existingString.includes(currentSubstring)) {
|
|
34
|
+
isSubsctringAlreadyContainedInABiggerString = true;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!isSubsctringAlreadyContainedInABiggerString) {
|
|
39
|
+
finalResultWithOnlyMaximalLengthStrings[currentSubstring] = matchResults[currentSubstring];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return finalResultWithOnlyMaximalLengthStrings;
|
|
43
|
+
};
|
|
44
|
+
exports.findCommonSubstrings = findCommonSubstrings;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interfaces/alphabet-settings-input.interface"), exports);
|
|
18
|
+
__exportStar(require("./helpers/object.helper"), exports);
|
|
19
|
+
__exportStar(require("./classes/key-alphabet.class"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blurpaper/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Shared base with interfaces and helper methods for blurpaper",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"build": "tsc -p ."
|
|
9
|
+
"build": "tsc -p .",
|
|
10
|
+
"build-and-publish": "npm run build && npm publish --access public"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [
|
|
12
13
|
"shared",
|