@ntnyq/utils 0.7.1 → 0.7.2

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 CHANGED
@@ -696,6 +696,24 @@ declare function ensurePrefix(input: string, prefix: string): string;
696
696
  //#region src/string/ensureSuffix.d.ts
697
697
  declare function ensureSuffix(input: string, suffix: string): string;
698
698
  //#endregion
699
+ //#region src/string/getSimilarity.d.ts
700
+ /**
701
+ * @copyright {@link https://github.com/stephenjjbrown/string-similarity-js}
702
+ */
703
+ interface GetStringSimilarityOptions {
704
+ /**
705
+ * The length of the slice to compare.
706
+ * @default 2
707
+ */
708
+ sliceLength?: number;
709
+ /**
710
+ * Whether to ignore case when comparing strings.
711
+ * @default false
712
+ */
713
+ caseSensitive?: boolean;
714
+ }
715
+ declare function getStringSimilarity(str1: string, str2: string, options?: GetStringSimilarityOptions): number;
716
+ //#endregion
699
717
  //#region src/constants/char.d.ts
700
718
  /**
701
719
  * Special chars
@@ -720,4 +738,4 @@ declare const RE_LINE_COMMENT: RegExp;
720
738
  */
721
739
  declare const RE_BLOCK_COMMENT: RegExp;
722
740
  //#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 };
741
+ 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, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.js CHANGED
@@ -725,6 +725,32 @@ function ensureSuffix(input, suffix) {
725
725
  return input.endsWith(suffix) ? input : `${input}${suffix}`;
726
726
  }
727
727
 
728
+ //#endregion
729
+ //#region src/string/getSimilarity.ts
730
+ function getStringSimilarity(str1, str2, options = {}) {
731
+ const { sliceLength = 2, caseSensitive = false } = options;
732
+ if (!caseSensitive) {
733
+ str1 = str1.toLowerCase();
734
+ str2 = str2.toLowerCase();
735
+ }
736
+ if (str1.length < sliceLength || str2.length < sliceLength) return 0;
737
+ const map = /* @__PURE__ */ new Map();
738
+ for (let i = 0; i < str1.length - (sliceLength - 1); i++) {
739
+ const subStr1 = str1.slice(i, i + sliceLength);
740
+ map.set(subStr1, (map.get(subStr1) || 0) + 1);
741
+ }
742
+ let match = 0;
743
+ for (let i = 0; i < str2.length - (sliceLength - 1); i++) {
744
+ const subStr2 = str2.slice(i, i + sliceLength);
745
+ const count = map.get(subStr2) || 0;
746
+ if (count > 0) {
747
+ match++;
748
+ map.set(subStr2, count - 1);
749
+ }
750
+ }
751
+ return match * 2 / (str1.length + str2.length - (sliceLength - 1) * 2);
752
+ }
753
+
728
754
  //#endregion
729
755
  //#region src/color/color.ts
730
756
  const pad2 = createPadString({
@@ -1027,4 +1053,4 @@ const RE_LINE_COMMENT = /\/\/.*/;
1027
1053
  const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
1028
1054
 
1029
1055
  //#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 };
1056
+ 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, 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.7.1",
4
+ "version": "0.7.2",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -38,9 +38,9 @@
38
38
  "nano-staged": "^0.8.0",
39
39
  "npm-run-all2": "^8.0.4",
40
40
  "prettier": "^3.5.3",
41
- "tsdown": "^0.12.6",
41
+ "tsdown": "^0.12.7",
42
42
  "typescript": "^5.8.3",
43
- "vitest": "^3.2.1"
43
+ "vitest": "^3.2.2"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18.18.0"