@ntnyq/utils 0.7.1 → 0.8.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 +28 -1
- package/dist/index.js +47 -9
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -185,6 +185,15 @@ declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?:
|
|
|
185
185
|
*/
|
|
186
186
|
declare const isBrowser: () => boolean;
|
|
187
187
|
//#endregion
|
|
188
|
+
//#region src/file/removeExtension.d.ts
|
|
189
|
+
/**
|
|
190
|
+
* Removes the file extension from a filename.
|
|
191
|
+
*
|
|
192
|
+
* @param filename - The filename to remove the extension from.
|
|
193
|
+
* @returns The filename without the extension.
|
|
194
|
+
*/
|
|
195
|
+
declare function removeFileExtension(filename: string): string;
|
|
196
|
+
//#endregion
|
|
188
197
|
//#region src/html/escape.d.ts
|
|
189
198
|
/**
|
|
190
199
|
* Escape html chars
|
|
@@ -696,6 +705,24 @@ declare function ensurePrefix(input: string, prefix: string): string;
|
|
|
696
705
|
//#region src/string/ensureSuffix.d.ts
|
|
697
706
|
declare function ensureSuffix(input: string, suffix: string): string;
|
|
698
707
|
//#endregion
|
|
708
|
+
//#region src/string/getSimilarity.d.ts
|
|
709
|
+
/**
|
|
710
|
+
* @copyright {@link https://github.com/stephenjjbrown/string-similarity-js}
|
|
711
|
+
*/
|
|
712
|
+
interface GetStringSimilarityOptions {
|
|
713
|
+
/**
|
|
714
|
+
* The length of the slice to compare.
|
|
715
|
+
* @default 2
|
|
716
|
+
*/
|
|
717
|
+
sliceLength?: number;
|
|
718
|
+
/**
|
|
719
|
+
* Whether to ignore case when comparing strings.
|
|
720
|
+
* @default false
|
|
721
|
+
*/
|
|
722
|
+
caseSensitive?: boolean;
|
|
723
|
+
}
|
|
724
|
+
declare function getStringSimilarity(str1: string, str2: string, options?: GetStringSimilarityOptions): number;
|
|
725
|
+
//#endregion
|
|
699
726
|
//#region src/constants/char.d.ts
|
|
700
727
|
/**
|
|
701
728
|
* Special chars
|
|
@@ -720,4 +747,4 @@ declare const RE_LINE_COMMENT: RegExp;
|
|
|
720
747
|
*/
|
|
721
748
|
declare const RE_BLOCK_COMMENT: RegExp;
|
|
722
749
|
//#endregion
|
|
723
|
-
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, OpenExternalURLOptions, Overwrite, Prettify, PrettifyV2, Primitive, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, RamdomNumberOptions, ResolvedOptions, SPECIAL_CHAR, SortObjectOptions, ThrottleDebounceOptions, ToIntegerOptions, Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
|
750
|
+
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, GetStringSimilarityOptions, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, OpenExternalURLOptions, Overwrite, Prettify, PrettifyV2, Primitive, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, RamdomNumberOptions, ResolvedOptions, SPECIAL_CHAR, SortObjectOptions, ThrottleDebounceOptions, ToIntegerOptions, Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, removeFileExtension, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -223,6 +223,18 @@ function isElementVisibleInViewport(element, targetWindow = window) {
|
|
|
223
223
|
*/
|
|
224
224
|
const isBrowser = () => typeof document !== "undefined";
|
|
225
225
|
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/file/removeExtension.ts
|
|
228
|
+
/**
|
|
229
|
+
* Removes the file extension from a filename.
|
|
230
|
+
*
|
|
231
|
+
* @param filename - The filename to remove the extension from.
|
|
232
|
+
* @returns The filename without the extension.
|
|
233
|
+
*/
|
|
234
|
+
function removeFileExtension(filename) {
|
|
235
|
+
return filename.replace(/\.[^/.]+$/, "");
|
|
236
|
+
}
|
|
237
|
+
|
|
226
238
|
//#endregion
|
|
227
239
|
//#region src/html/escape.ts
|
|
228
240
|
const htmlEscapeMap = {
|
|
@@ -302,10 +314,10 @@ function cAF(id) {
|
|
|
302
314
|
* @module Time
|
|
303
315
|
*/
|
|
304
316
|
const ONE_SECOND_MILLSECONDS = 1e3;
|
|
305
|
-
const ONE_MINUTE_MILLSECONDS = 60 *
|
|
306
|
-
const ONE_HOUR_MILLSECONDS = 60 *
|
|
307
|
-
const ONE_DAY_MILLSECONDS = 24 *
|
|
308
|
-
const ONE_WEEK_MILLSECONDS = 7 *
|
|
317
|
+
const ONE_MINUTE_MILLSECONDS = 60 * 1e3;
|
|
318
|
+
const ONE_HOUR_MILLSECONDS = 60 * 60 * 1e3;
|
|
319
|
+
const ONE_DAY_MILLSECONDS = 24 * 60 * 60 * 1e3;
|
|
320
|
+
const ONE_WEEK_MILLSECONDS = 7 * 24 * 60 * 60 * 1e3;
|
|
309
321
|
function seconds(count) {
|
|
310
322
|
return count * ONE_SECOND_MILLSECONDS;
|
|
311
323
|
}
|
|
@@ -725,12 +737,34 @@ function ensureSuffix(input, suffix) {
|
|
|
725
737
|
return input.endsWith(suffix) ? input : `${input}${suffix}`;
|
|
726
738
|
}
|
|
727
739
|
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/string/getSimilarity.ts
|
|
742
|
+
function getStringSimilarity(str1, str2, options = {}) {
|
|
743
|
+
const { sliceLength = 2, caseSensitive = false } = options;
|
|
744
|
+
if (!caseSensitive) {
|
|
745
|
+
str1 = str1.toLowerCase();
|
|
746
|
+
str2 = str2.toLowerCase();
|
|
747
|
+
}
|
|
748
|
+
if (str1.length < sliceLength || str2.length < sliceLength) return 0;
|
|
749
|
+
const map = /* @__PURE__ */ new Map();
|
|
750
|
+
for (let i = 0; i < str1.length - (sliceLength - 1); i++) {
|
|
751
|
+
const subStr1 = str1.slice(i, i + sliceLength);
|
|
752
|
+
map.set(subStr1, (map.get(subStr1) || 0) + 1);
|
|
753
|
+
}
|
|
754
|
+
let match = 0;
|
|
755
|
+
for (let i = 0; i < str2.length - (sliceLength - 1); i++) {
|
|
756
|
+
const subStr2 = str2.slice(i, i + sliceLength);
|
|
757
|
+
const count = map.get(subStr2) || 0;
|
|
758
|
+
if (count > 0) {
|
|
759
|
+
match++;
|
|
760
|
+
map.set(subStr2, count - 1);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return match * 2 / (str1.length + str2.length - (sliceLength - 1) * 2);
|
|
764
|
+
}
|
|
765
|
+
|
|
728
766
|
//#endregion
|
|
729
767
|
//#region src/color/color.ts
|
|
730
|
-
const pad2 = createPadString({
|
|
731
|
-
length: 2,
|
|
732
|
-
char: "0"
|
|
733
|
-
});
|
|
734
768
|
const RE_VALID_HEX_COLOR = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
|
|
735
769
|
function validateHexColor(hex) {
|
|
736
770
|
if (hex.length !== 4 && hex.length !== 7) return false;
|
|
@@ -776,6 +810,10 @@ var Color = class Color {
|
|
|
776
810
|
return !this.isDark;
|
|
777
811
|
}
|
|
778
812
|
toHexString(isUpperCase = true) {
|
|
813
|
+
const pad2 = createPadString({
|
|
814
|
+
length: 2,
|
|
815
|
+
char: "0"
|
|
816
|
+
});
|
|
779
817
|
const hexString = `#${pad2(this.red.toString(16))}${pad2(this.green.toString(16))}${pad2(this.blue.toString(16))}`;
|
|
780
818
|
return isUpperCase ? hexString.toUpperCase() : hexString;
|
|
781
819
|
}
|
|
@@ -1027,4 +1065,4 @@ const RE_LINE_COMMENT = /\/\/.*/;
|
|
|
1027
1065
|
const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1028
1066
|
|
|
1029
1067
|
//#endregion
|
|
1030
|
-
export { Color, NOOP, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
|
1068
|
+
export { Color, NOOP, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, removeFileExtension, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
],
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@ntnyq/eslint-config": "^5.0.0
|
|
34
|
-
"@ntnyq/prettier-config": "^
|
|
35
|
-
"bumpp": "^10.
|
|
36
|
-
"eslint": "^9.
|
|
33
|
+
"@ntnyq/eslint-config": "^5.0.0",
|
|
34
|
+
"@ntnyq/prettier-config": "^3.0.1",
|
|
35
|
+
"bumpp": "^10.2.0",
|
|
36
|
+
"eslint": "^9.30.1",
|
|
37
37
|
"husky": "^9.1.7",
|
|
38
38
|
"nano-staged": "^0.8.0",
|
|
39
39
|
"npm-run-all2": "^8.0.4",
|
|
40
|
-
"prettier": "^3.
|
|
41
|
-
"tsdown": "^0.12.
|
|
40
|
+
"prettier": "^3.6.2",
|
|
41
|
+
"tsdown": "^0.12.9",
|
|
42
42
|
"typescript": "^5.8.3",
|
|
43
|
-
"vitest": "^3.2.
|
|
43
|
+
"vitest": "^3.2.4"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18.18.0"
|