@blurpaper/shared 1.0.3 → 1.0.5
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.
|
@@ -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
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from "./interfaces/alphabet-settings-input.interface";
|
|
2
|
+
export * from "./interfaces/start-end.interface";
|
|
2
3
|
export * from "./helpers/object.helper";
|
|
4
|
+
export * from "./helpers/string.helper";
|
|
3
5
|
export * from "./classes/key-alphabet.class";
|
|
4
6
|
export * from "./constants";
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./interfaces/alphabet-settings-input.interface"), exports);
|
|
18
|
+
__exportStar(require("./interfaces/start-end.interface"), exports);
|
|
18
19
|
__exportStar(require("./helpers/object.helper"), exports);
|
|
20
|
+
__exportStar(require("./helpers/string.helper"), exports);
|
|
19
21
|
__exportStar(require("./classes/key-alphabet.class"), exports);
|
|
20
22
|
__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.5",
|
|
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",
|