@naturalcycles/js-lib 14.87.0 → 14.88.0
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/string/leven.d.ts +6 -0
- package/dist/string/leven.js +75 -0
- package/dist-esm/index.js +1 -0
- package/dist-esm/string/leven.js +71 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/string/leven.ts +86 -0
package/dist/index.d.ts
CHANGED
|
@@ -60,5 +60,6 @@ export * from './string/safeJsonStringify';
|
|
|
60
60
|
import { PQueue, PQueueCfg } from './promise/pQueue';
|
|
61
61
|
export * from './seq/seq';
|
|
62
62
|
export * from './math/stack.util';
|
|
63
|
+
export * from './string/leven';
|
|
63
64
|
export type { AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateTime, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
64
65
|
export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
|
package/dist/index.js
CHANGED
|
@@ -92,3 +92,4 @@ const pQueue_1 = require("./promise/pQueue");
|
|
|
92
92
|
Object.defineProperty(exports, "PQueue", { enumerable: true, get: function () { return pQueue_1.PQueue; } });
|
|
93
93
|
(0, tslib_1.__exportStar)(require("./seq/seq"), exports);
|
|
94
94
|
(0, tslib_1.__exportStar)(require("./math/stack.util"), exports);
|
|
95
|
+
(0, tslib_1.__exportStar)(require("./string/leven"), exports);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._leven = void 0;
|
|
4
|
+
const array = [];
|
|
5
|
+
const characterCodeCache = [];
|
|
6
|
+
/* eslint-disable unicorn/prefer-code-point, no-bitwise */
|
|
7
|
+
/**
|
|
8
|
+
* Modified version of: https://github.com/sindresorhus/leven/
|
|
9
|
+
*
|
|
10
|
+
* Returns a Levenshtein distance between first and second word.
|
|
11
|
+
*/
|
|
12
|
+
function _leven(first, second) {
|
|
13
|
+
if (first === second) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const swap = first;
|
|
17
|
+
// Swapping the strings if `a` is longer than `b` so we know which one is the
|
|
18
|
+
// shortest & which one is the longest
|
|
19
|
+
if (first.length > second.length) {
|
|
20
|
+
first = second;
|
|
21
|
+
second = swap;
|
|
22
|
+
}
|
|
23
|
+
let firstLength = first.length;
|
|
24
|
+
let secondLength = second.length;
|
|
25
|
+
// Performing suffix trimming:
|
|
26
|
+
// We can linearly drop suffix common to both strings since they
|
|
27
|
+
// don't increase distance at all
|
|
28
|
+
// Note: `~-` is the bitwise way to perform a `- 1` operation
|
|
29
|
+
while (firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength)) {
|
|
30
|
+
firstLength--;
|
|
31
|
+
secondLength--;
|
|
32
|
+
}
|
|
33
|
+
// Performing prefix trimming
|
|
34
|
+
// We can linearly drop prefix common to both strings since they
|
|
35
|
+
// don't increase distance at all
|
|
36
|
+
let start = 0;
|
|
37
|
+
while (start < firstLength && first.charCodeAt(start) === second.charCodeAt(start)) {
|
|
38
|
+
start++;
|
|
39
|
+
}
|
|
40
|
+
firstLength -= start;
|
|
41
|
+
secondLength -= start;
|
|
42
|
+
if (firstLength === 0) {
|
|
43
|
+
return secondLength;
|
|
44
|
+
}
|
|
45
|
+
let bCharacterCode;
|
|
46
|
+
let result;
|
|
47
|
+
let temporary;
|
|
48
|
+
let temporary2;
|
|
49
|
+
let index = 0;
|
|
50
|
+
let index2 = 0;
|
|
51
|
+
while (index < firstLength) {
|
|
52
|
+
characterCodeCache[index] = first.charCodeAt(start + index);
|
|
53
|
+
array[index] = ++index;
|
|
54
|
+
}
|
|
55
|
+
while (index2 < secondLength) {
|
|
56
|
+
bCharacterCode = second.charCodeAt(start + index2);
|
|
57
|
+
temporary = index2++;
|
|
58
|
+
result = index2;
|
|
59
|
+
for (index = 0; index < firstLength; index++) {
|
|
60
|
+
temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1;
|
|
61
|
+
temporary = array[index];
|
|
62
|
+
// eslint-disable-next-line no-multi-assign
|
|
63
|
+
result = array[index] =
|
|
64
|
+
temporary > result
|
|
65
|
+
? temporary2 > result
|
|
66
|
+
? result + 1
|
|
67
|
+
: temporary2
|
|
68
|
+
: temporary2 > temporary
|
|
69
|
+
? temporary + 1
|
|
70
|
+
: temporary2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
exports._leven = _leven;
|
package/dist-esm/index.js
CHANGED
|
@@ -56,4 +56,5 @@ export * from './string/safeJsonStringify';
|
|
|
56
56
|
import { PQueue } from './promise/pQueue';
|
|
57
57
|
export * from './seq/seq';
|
|
58
58
|
export * from './math/stack.util';
|
|
59
|
+
export * from './string/leven';
|
|
59
60
|
export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const array = [];
|
|
2
|
+
const characterCodeCache = [];
|
|
3
|
+
/* eslint-disable unicorn/prefer-code-point, no-bitwise */
|
|
4
|
+
/**
|
|
5
|
+
* Modified version of: https://github.com/sindresorhus/leven/
|
|
6
|
+
*
|
|
7
|
+
* Returns a Levenshtein distance between first and second word.
|
|
8
|
+
*/
|
|
9
|
+
export function _leven(first, second) {
|
|
10
|
+
if (first === second) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
const swap = first;
|
|
14
|
+
// Swapping the strings if `a` is longer than `b` so we know which one is the
|
|
15
|
+
// shortest & which one is the longest
|
|
16
|
+
if (first.length > second.length) {
|
|
17
|
+
first = second;
|
|
18
|
+
second = swap;
|
|
19
|
+
}
|
|
20
|
+
let firstLength = first.length;
|
|
21
|
+
let secondLength = second.length;
|
|
22
|
+
// Performing suffix trimming:
|
|
23
|
+
// We can linearly drop suffix common to both strings since they
|
|
24
|
+
// don't increase distance at all
|
|
25
|
+
// Note: `~-` is the bitwise way to perform a `- 1` operation
|
|
26
|
+
while (firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength)) {
|
|
27
|
+
firstLength--;
|
|
28
|
+
secondLength--;
|
|
29
|
+
}
|
|
30
|
+
// Performing prefix trimming
|
|
31
|
+
// We can linearly drop prefix common to both strings since they
|
|
32
|
+
// don't increase distance at all
|
|
33
|
+
let start = 0;
|
|
34
|
+
while (start < firstLength && first.charCodeAt(start) === second.charCodeAt(start)) {
|
|
35
|
+
start++;
|
|
36
|
+
}
|
|
37
|
+
firstLength -= start;
|
|
38
|
+
secondLength -= start;
|
|
39
|
+
if (firstLength === 0) {
|
|
40
|
+
return secondLength;
|
|
41
|
+
}
|
|
42
|
+
let bCharacterCode;
|
|
43
|
+
let result;
|
|
44
|
+
let temporary;
|
|
45
|
+
let temporary2;
|
|
46
|
+
let index = 0;
|
|
47
|
+
let index2 = 0;
|
|
48
|
+
while (index < firstLength) {
|
|
49
|
+
characterCodeCache[index] = first.charCodeAt(start + index);
|
|
50
|
+
array[index] = ++index;
|
|
51
|
+
}
|
|
52
|
+
while (index2 < secondLength) {
|
|
53
|
+
bCharacterCode = second.charCodeAt(start + index2);
|
|
54
|
+
temporary = index2++;
|
|
55
|
+
result = index2;
|
|
56
|
+
for (index = 0; index < firstLength; index++) {
|
|
57
|
+
temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1;
|
|
58
|
+
temporary = array[index];
|
|
59
|
+
// eslint-disable-next-line no-multi-assign
|
|
60
|
+
result = array[index] =
|
|
61
|
+
temporary > result
|
|
62
|
+
? temporary2 > result
|
|
63
|
+
? result + 1
|
|
64
|
+
: temporary2
|
|
65
|
+
: temporary2 > temporary
|
|
66
|
+
? temporary + 1
|
|
67
|
+
: temporary2;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const array: number[] = []
|
|
2
|
+
const characterCodeCache: number[] = []
|
|
3
|
+
|
|
4
|
+
/* eslint-disable unicorn/prefer-code-point, no-bitwise */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Modified version of: https://github.com/sindresorhus/leven/
|
|
8
|
+
*
|
|
9
|
+
* Returns a Levenshtein distance between first and second word.
|
|
10
|
+
*/
|
|
11
|
+
export function _leven(first: string, second: string): number {
|
|
12
|
+
if (first === second) {
|
|
13
|
+
return 0
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const swap = first
|
|
17
|
+
|
|
18
|
+
// Swapping the strings if `a` is longer than `b` so we know which one is the
|
|
19
|
+
// shortest & which one is the longest
|
|
20
|
+
if (first.length > second.length) {
|
|
21
|
+
first = second
|
|
22
|
+
second = swap
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let firstLength = first.length
|
|
26
|
+
let secondLength = second.length
|
|
27
|
+
|
|
28
|
+
// Performing suffix trimming:
|
|
29
|
+
// We can linearly drop suffix common to both strings since they
|
|
30
|
+
// don't increase distance at all
|
|
31
|
+
// Note: `~-` is the bitwise way to perform a `- 1` operation
|
|
32
|
+
while (firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength)) {
|
|
33
|
+
firstLength--
|
|
34
|
+
secondLength--
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Performing prefix trimming
|
|
38
|
+
// We can linearly drop prefix common to both strings since they
|
|
39
|
+
// don't increase distance at all
|
|
40
|
+
let start = 0
|
|
41
|
+
|
|
42
|
+
while (start < firstLength && first.charCodeAt(start) === second.charCodeAt(start)) {
|
|
43
|
+
start++
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
firstLength -= start
|
|
47
|
+
secondLength -= start
|
|
48
|
+
|
|
49
|
+
if (firstLength === 0) {
|
|
50
|
+
return secondLength
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let bCharacterCode
|
|
54
|
+
let result: number
|
|
55
|
+
let temporary: number
|
|
56
|
+
let temporary2: number
|
|
57
|
+
let index = 0
|
|
58
|
+
let index2 = 0
|
|
59
|
+
|
|
60
|
+
while (index < firstLength) {
|
|
61
|
+
characterCodeCache[index] = first.charCodeAt(start + index)
|
|
62
|
+
array[index] = ++index
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
while (index2 < secondLength) {
|
|
66
|
+
bCharacterCode = second.charCodeAt(start + index2)
|
|
67
|
+
temporary = index2++
|
|
68
|
+
result = index2
|
|
69
|
+
|
|
70
|
+
for (index = 0; index < firstLength; index++) {
|
|
71
|
+
temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1
|
|
72
|
+
temporary = array[index]!
|
|
73
|
+
// eslint-disable-next-line no-multi-assign
|
|
74
|
+
result = array[index] =
|
|
75
|
+
temporary > result
|
|
76
|
+
? temporary2 > result
|
|
77
|
+
? result + 1
|
|
78
|
+
: temporary2
|
|
79
|
+
: temporary2 > temporary
|
|
80
|
+
? temporary + 1
|
|
81
|
+
: temporary2
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result!
|
|
86
|
+
}
|