@react-hive/honey-utils 1.1.0 → 1.3.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/README.md +292 -0
- package/dist/README.md +292 -0
- package/dist/dom.d.ts +13 -0
- package/dist/guards.d.ts +148 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.dev.cjs +291 -6
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/math.d.ts +29 -0
- package/dist/string.d.ts +12 -3
- package/package.json +11 -3
package/dist/guards.d.ts
CHANGED
|
@@ -1,8 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is null.
|
|
3
|
+
*
|
|
4
|
+
* @param value - The value to check.
|
|
5
|
+
*
|
|
6
|
+
* @returns `true` if the value is null; otherwise, `false`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isNull: (value: unknown) => value is null;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a value is a string.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to check.
|
|
13
|
+
*
|
|
14
|
+
* @returns `true` if the value is a string; otherwise, `false`.
|
|
15
|
+
*/
|
|
1
16
|
export declare const isString: (value: unknown) => value is string;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a value is a number.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The value to check.
|
|
21
|
+
*
|
|
22
|
+
* @returns `true` if the value is a number; otherwise, `false`.
|
|
23
|
+
*/
|
|
2
24
|
export declare const isNumber: (value: unknown) => value is number;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a value is a boolean.
|
|
27
|
+
*
|
|
28
|
+
* @param value - The value to check.
|
|
29
|
+
*
|
|
30
|
+
* @returns `true` if the value is a boolean; otherwise, `false`.
|
|
31
|
+
*/
|
|
3
32
|
export declare const isBool: (value: unknown) => value is boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a value is an object.
|
|
35
|
+
*
|
|
36
|
+
* @param value - The value to check.
|
|
37
|
+
*
|
|
38
|
+
* @returns `true` if the value is an object; otherwise, `false`.
|
|
39
|
+
*/
|
|
4
40
|
export declare const isObject: (value: unknown) => value is object;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a value is an empty object (no own enumerable properties).
|
|
43
|
+
*
|
|
44
|
+
* @param value - The value to check.
|
|
45
|
+
*
|
|
46
|
+
* @returns `true` if the value is an empty object; otherwise, `false`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const isEmptyObject: (value: unknown) => value is Record<string, never>;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a value is an array.
|
|
51
|
+
*
|
|
52
|
+
* @param value - The value to check.
|
|
53
|
+
*
|
|
54
|
+
* @returns `true` if the value is an array; otherwise, `false`.
|
|
55
|
+
*/
|
|
56
|
+
export declare const isArray: (value: unknown) => value is unknown[];
|
|
57
|
+
/**
|
|
58
|
+
* Checks if a value is an empty array.
|
|
59
|
+
*
|
|
60
|
+
* @param value - The value to check.
|
|
61
|
+
*
|
|
62
|
+
* @returns `true` if the value is an empty array; otherwise, `false`.
|
|
63
|
+
*/
|
|
64
|
+
export declare const isEmptyArray: (value: unknown) => value is [];
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a value is a function.
|
|
67
|
+
*
|
|
68
|
+
* @param value - The value to check.
|
|
69
|
+
*
|
|
70
|
+
* @returns `true` if the value is a function; otherwise, `false`.
|
|
71
|
+
*/
|
|
5
72
|
export declare const isFunction: (value: unknown) => value is Function;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a value is a Promise.
|
|
75
|
+
*
|
|
76
|
+
* @template T - The type of the value that the Promise resolves to.
|
|
77
|
+
*
|
|
78
|
+
* @param value - The value to check.
|
|
79
|
+
*
|
|
80
|
+
* @returns `true` if the value is a Promise; otherwise, `false`.
|
|
81
|
+
*/
|
|
6
82
|
export declare const isPromise: <T = unknown>(value: unknown) => value is Promise<T>;
|
|
7
83
|
/**
|
|
8
84
|
* Checks if a value is null or undefined.
|
|
@@ -25,3 +101,75 @@ export declare const isNil: (value: unknown) => value is null | undefined;
|
|
|
25
101
|
* @returns `true` if the value is empty; otherwise, `false`.
|
|
26
102
|
*/
|
|
27
103
|
export declare const isNilOrEmptyString: (value: unknown) => value is null | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a value is a Date object.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The value to check.
|
|
108
|
+
*
|
|
109
|
+
* @returns `true` if the value is a Date object; otherwise, `false`.
|
|
110
|
+
*/
|
|
111
|
+
export declare const isDate: (value: unknown) => value is Date;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if a value is a valid Date object (not Invalid Date).
|
|
114
|
+
*
|
|
115
|
+
* @param value - The value to check.
|
|
116
|
+
*
|
|
117
|
+
* @returns `true` if the value is a valid Date object; otherwise, `false`.
|
|
118
|
+
*/
|
|
119
|
+
export declare const isValidDate: (value: unknown) => value is Date;
|
|
120
|
+
/**
|
|
121
|
+
* Checks if a value is a RegExp object.
|
|
122
|
+
*
|
|
123
|
+
* @param value - The value to check.
|
|
124
|
+
*
|
|
125
|
+
* @returns `true` if the value is a RegExp object; otherwise, `false`.
|
|
126
|
+
*/
|
|
127
|
+
export declare const isRegExp: (value: unknown) => value is RegExp;
|
|
128
|
+
/**
|
|
129
|
+
* Checks if a value is a Map.
|
|
130
|
+
*
|
|
131
|
+
* @param value - The value to check.
|
|
132
|
+
*
|
|
133
|
+
* @returns `true` if the value is a Map; otherwise, `false`.
|
|
134
|
+
*/
|
|
135
|
+
export declare const isMap: (value: unknown) => value is Map<unknown, unknown>;
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a value is a Set.
|
|
138
|
+
*
|
|
139
|
+
* @param value - The value to check.
|
|
140
|
+
*
|
|
141
|
+
* @returns `true` if the value is a Set; otherwise, `false`.
|
|
142
|
+
*/
|
|
143
|
+
export declare const isSet: (value: unknown) => value is Set<unknown>;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a value is a Symbol.
|
|
146
|
+
*
|
|
147
|
+
* @param value - The value to check.
|
|
148
|
+
*
|
|
149
|
+
* @returns `true` if the value is a Symbol; otherwise, `false`.
|
|
150
|
+
*/
|
|
151
|
+
export declare const isSymbol: (value: unknown) => value is symbol;
|
|
152
|
+
/**
|
|
153
|
+
* Checks if a value is undefined.
|
|
154
|
+
*
|
|
155
|
+
* @param value - The value to check.
|
|
156
|
+
*
|
|
157
|
+
* @returns `true` if the value is undefined; otherwise, `false`.
|
|
158
|
+
*/
|
|
159
|
+
export declare const isUndefined: (value: unknown) => value is undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Checks if a value is a finite number.
|
|
162
|
+
*
|
|
163
|
+
* @param value - The value to check.
|
|
164
|
+
*
|
|
165
|
+
* @returns `true` if the value is a finite number; otherwise, `false`.
|
|
166
|
+
*/
|
|
167
|
+
export declare const isFiniteNumber: (value: unknown) => value is number;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a value is an integer.
|
|
170
|
+
*
|
|
171
|
+
* @param value - The value to check.
|
|
172
|
+
*
|
|
173
|
+
* @returns `true` if the value is an integer; otherwise, `false`.
|
|
174
|
+
*/
|
|
175
|
+
export declare const isInteger: (value: unknown) => value is number;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(o
|
|
1
|
+
(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{assert:()=>I,boolFilter:()=>a,calculateEuclideanDistance:()=>C,calculateMovingSpeed:()=>D,calculatePercentage:()=>T,camelToDashCase:()=>r,getTransformationValues:()=>x,hashString:()=>n,invokeIfFunction:()=>l,isArray:()=>b,isBool:()=>f,isDate:()=>j,isEmptyArray:()=>m,isEmptyObject:()=>g,isFiniteNumber:()=>M,isFunction:()=>d,isInteger:()=>P,isMap:()=>w,isNil:()=>h,isNilOrEmptyString:()=>O,isNull:()=>c,isNumber:()=>u,isObject:()=>y,isPromise:()=>S,isRegExp:()=>v,isSet:()=>A,isString:()=>p,isSymbol:()=>E,isUndefined:()=>F,isValidDate:()=>N,noop:()=>s,splitStringIntoWords:()=>i,toKebabCase:()=>o});const o=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),r=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),i=e=>e.split(" ").filter(Boolean),n=e=>{let t=5381;for(let o=0;o<e.length;o++)t=33*t^e.charCodeAt(o);return(t>>>0).toString(36)},a=e=>e.filter(Boolean),s=()=>{},l=(e,...t)=>"function"==typeof e?e(...t):e,c=e=>null===e,p=e=>"string"==typeof e,u=e=>"number"==typeof e,f=e=>"boolean"==typeof e,y=e=>"object"==typeof e,g=e=>y(e)&&!c(e)&&0===Object.keys(e).length,b=e=>Array.isArray(e),m=e=>b(e)&&0===e.length,d=e=>"function"==typeof e,S=e=>d(e?.then),h=e=>null==e,O=e=>""===e||h(e),j=e=>e instanceof Date,N=e=>j(e)&&!isNaN(e.getTime()),v=e=>e instanceof RegExp,w=e=>e instanceof Map,A=e=>e instanceof Set,E=e=>"symbol"==typeof e,F=e=>void 0===e,M=e=>u(e)&&isFinite(e),P=e=>u(e)&&Number.isInteger(e),C=(e,t,o,r)=>{const i=o-e,n=r-t;return Math.sqrt(i**2+n**2)},D=(e,t)=>Math.abs(e/t),T=(e,t)=>e*t/100,x=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0};const o=t[1].split(", ");return{translateX:parseFloat(o[4]),translateY:parseFloat(o[5])}};function I(e,t){if(!e)throw new Error(t)}module.exports=t})();
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,wPCLhD,MAAMC,EAAeC,GAC1BA,EAAIC,QAAQ,qBAAsB,SAASC,cA0BhCC,EAAcH,IACzB,IAAII,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAIM,OAAQD,IAC9BD,EAAe,GAAPA,EAAaJ,EAAIO,WAAWF,GAGtC,OAAQD,IAAS,GAAGI,SAAS,KCtBlBC,EAAiBC,GAC5BA,EAAMC,OAAOC,SCbFC,EAAO,OAcPC,EAAmB,CAC9BC,KACGC,IAC0B,mBAAVD,EAAwBA,KAAuCC,GAAQD,ECjB/EE,EAAYnB,GAAqD,iBAAVA,EAEvDoB,EAAYpB,GAAqD,iBAAVA,EAEvDqB,EAAUrB,GAAsD,kBAAVA,EAEtDsB,EAAYtB,GAAqD,iBAAVA,EAEvDuB,EAAcvB,GAAoC,mBAAVA,EAExCwB,EAA0BxB,GACrCuB,EAAYvB,GAAsByB,MASvBC,EAAS1B,GACpBA,QAcW2B,EAAsB3B,GACvB,KAAVA,GAAgB0B,EAAM1B,GC/BjB,SAAS4B,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,C","sources":["webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param str - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (str: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < str.length; i++) {\n hash = (hash * 33) ^ str.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","str","replace","toLowerCase","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","filter","Boolean","noop","invokeIfFunction","input","args","isString","isNumber","isBool","isObject","isFunction","isPromise","then","isNil","isNilOrEmptyString","assert","condition","message","Error"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,2mBCLhD,MAAMC,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAElCC,EAAmBH,GAC9BA,EAAMC,QAAQ,SAAUG,GAAU,IAAIA,EAAOF,iBASlCG,EAAwBL,GAA4BA,EAAMM,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcT,IACzB,IAAIU,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIX,EAAMY,OAAQD,IAChCD,EAAe,GAAPA,EAAaV,EAAMa,WAAWF,GAGxC,OAAQD,IAAS,GAAGI,SAAS,KClClBC,EAAiBC,GAC5BA,EAAMT,OAAOC,SCbFS,EAAO,OAcPC,EAAmB,CAC9BlB,KACGmB,IAC0B,mBAAVnB,EAAwBA,KAAuCmB,GAAQnB,ECV/EoB,EAAUtB,GAA4C,OAAVA,EAS5CuB,EAAYvB,GAAqD,iBAAVA,EASvDwB,EAAYxB,GAAqD,iBAAVA,EASvDyB,EAAUzB,GAAsD,kBAAVA,EAStD0B,EAAY1B,GAAqD,iBAAVA,EASvD2B,EAAiB3B,GAC5B0B,EAAS1B,KAAWsB,EAAOtB,IAAwC,IAA9BX,OAAOuC,KAAK5B,GAAOc,OAS7Ce,EAAW7B,GAAuC8B,MAAMD,QAAQ7B,GAShE+B,EAAgB/B,GAAgC6B,EAAQ7B,IAA2B,IAAjBA,EAAMc,OASxEkB,EAAchC,GAAoC,mBAAVA,EAWxCiC,EAA0BjC,GACrCgC,EAAYhC,GAAsBkC,MASvBC,EAASnC,GACpBA,QAcWoC,EAAsBpC,GACvB,KAAVA,GAAgBmC,EAAMnC,GASXqC,EAAUrC,GAAkCA,aAAiBsC,KAS7DC,EAAevC,GAC1BqC,EAAOrC,KAAWwC,MAAMxC,EAAMyC,WASnBC,EAAY1C,GAAoCA,aAAiB2C,OASjEC,EAAS5C,GAAmDA,aAAiB6C,IAS7EC,EAAS9C,GAA0CA,aAAiB+C,IASpEC,EAAYhD,GAAqD,iBAAVA,EASvDiD,EAAejD,QAAiDkD,IAAVlD,EAStDmD,EAAkBnD,GAC7BwB,EAASxB,IAAUoD,SAASpD,GASjBqD,EAAarD,GACxBwB,EAASxB,IAAUsD,OAAOD,UAAUrD,GC/LzBuD,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOK,KAAKC,KAAKH,GAAU,EAAIC,GAAU,IAW9BG,EAAuB,CAACC,EAAeC,IAClDJ,KAAKK,IAAIF,EAAQC,GAUNE,EAAsB,CAACpE,EAAeqE,IACzCrE,EAAQqE,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGhE,MAAM,MAKxC,MAAO,CACLqE,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,MCpBzC,SAASE,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,C","sources":["webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","input","replace","toLowerCase","camelToDashCase","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","noop","invokeIfFunction","args","isNull","isString","isNumber","isBool","isObject","isEmptyObject","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isNil","isNilOrEmptyString","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","Math","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat","assert","condition","message","Error"],"sourceRoot":""}
|
package/dist/index.d.ts
CHANGED
package/dist/index.dev.cjs
CHANGED
|
@@ -27,6 +27,45 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
27
27
|
const boolFilter = (array) => array.filter(Boolean);
|
|
28
28
|
|
|
29
29
|
|
|
30
|
+
/***/ }),
|
|
31
|
+
|
|
32
|
+
/***/ "./src/dom.ts":
|
|
33
|
+
/*!********************!*\
|
|
34
|
+
!*** ./src/dom.ts ***!
|
|
35
|
+
\********************/
|
|
36
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
37
|
+
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
/* harmony export */ getTransformationValues: () => (/* binding */ getTransformationValues)
|
|
41
|
+
/* harmony export */ });
|
|
42
|
+
/**
|
|
43
|
+
* Get various transformation values from the transformation matrix of an element.
|
|
44
|
+
*
|
|
45
|
+
* @param element - The element with a transformation applied.
|
|
46
|
+
*
|
|
47
|
+
* @returns An object containing transformation values.
|
|
48
|
+
*/
|
|
49
|
+
const getTransformationValues = (element) => {
|
|
50
|
+
const computedStyles = window.getComputedStyle(element);
|
|
51
|
+
const transformValue = computedStyles.getPropertyValue('transform');
|
|
52
|
+
const matrix = transformValue.match(/^matrix\((.+)\)$/);
|
|
53
|
+
if (!matrix) {
|
|
54
|
+
return {
|
|
55
|
+
translateX: 0,
|
|
56
|
+
translateY: 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const transformMatrix = matrix[1].split(', ');
|
|
60
|
+
const translateX = parseFloat(transformMatrix[4]);
|
|
61
|
+
const translateY = parseFloat(transformMatrix[5]);
|
|
62
|
+
return {
|
|
63
|
+
translateX,
|
|
64
|
+
translateY,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
30
69
|
/***/ }),
|
|
31
70
|
|
|
32
71
|
/***/ "./src/function.ts":
|
|
@@ -66,20 +105,109 @@ const invokeIfFunction = (input, ...args) => (typeof input === 'function' ? inpu
|
|
|
66
105
|
|
|
67
106
|
__webpack_require__.r(__webpack_exports__);
|
|
68
107
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
108
|
+
/* harmony export */ isArray: () => (/* binding */ isArray),
|
|
69
109
|
/* harmony export */ isBool: () => (/* binding */ isBool),
|
|
110
|
+
/* harmony export */ isDate: () => (/* binding */ isDate),
|
|
111
|
+
/* harmony export */ isEmptyArray: () => (/* binding */ isEmptyArray),
|
|
112
|
+
/* harmony export */ isEmptyObject: () => (/* binding */ isEmptyObject),
|
|
113
|
+
/* harmony export */ isFiniteNumber: () => (/* binding */ isFiniteNumber),
|
|
70
114
|
/* harmony export */ isFunction: () => (/* binding */ isFunction),
|
|
115
|
+
/* harmony export */ isInteger: () => (/* binding */ isInteger),
|
|
116
|
+
/* harmony export */ isMap: () => (/* binding */ isMap),
|
|
71
117
|
/* harmony export */ isNil: () => (/* binding */ isNil),
|
|
72
118
|
/* harmony export */ isNilOrEmptyString: () => (/* binding */ isNilOrEmptyString),
|
|
119
|
+
/* harmony export */ isNull: () => (/* binding */ isNull),
|
|
73
120
|
/* harmony export */ isNumber: () => (/* binding */ isNumber),
|
|
74
121
|
/* harmony export */ isObject: () => (/* binding */ isObject),
|
|
75
122
|
/* harmony export */ isPromise: () => (/* binding */ isPromise),
|
|
76
|
-
/* harmony export */
|
|
123
|
+
/* harmony export */ isRegExp: () => (/* binding */ isRegExp),
|
|
124
|
+
/* harmony export */ isSet: () => (/* binding */ isSet),
|
|
125
|
+
/* harmony export */ isString: () => (/* binding */ isString),
|
|
126
|
+
/* harmony export */ isSymbol: () => (/* binding */ isSymbol),
|
|
127
|
+
/* harmony export */ isUndefined: () => (/* binding */ isUndefined),
|
|
128
|
+
/* harmony export */ isValidDate: () => (/* binding */ isValidDate)
|
|
77
129
|
/* harmony export */ });
|
|
130
|
+
/**
|
|
131
|
+
* Checks if a value is null.
|
|
132
|
+
*
|
|
133
|
+
* @param value - The value to check.
|
|
134
|
+
*
|
|
135
|
+
* @returns `true` if the value is null; otherwise, `false`.
|
|
136
|
+
*/
|
|
137
|
+
const isNull = (value) => value === null;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a value is a string.
|
|
140
|
+
*
|
|
141
|
+
* @param value - The value to check.
|
|
142
|
+
*
|
|
143
|
+
* @returns `true` if the value is a string; otherwise, `false`.
|
|
144
|
+
*/
|
|
78
145
|
const isString = (value) => typeof value === 'string';
|
|
146
|
+
/**
|
|
147
|
+
* Checks if a value is a number.
|
|
148
|
+
*
|
|
149
|
+
* @param value - The value to check.
|
|
150
|
+
*
|
|
151
|
+
* @returns `true` if the value is a number; otherwise, `false`.
|
|
152
|
+
*/
|
|
79
153
|
const isNumber = (value) => typeof value === 'number';
|
|
154
|
+
/**
|
|
155
|
+
* Checks if a value is a boolean.
|
|
156
|
+
*
|
|
157
|
+
* @param value - The value to check.
|
|
158
|
+
*
|
|
159
|
+
* @returns `true` if the value is a boolean; otherwise, `false`.
|
|
160
|
+
*/
|
|
80
161
|
const isBool = (value) => typeof value === 'boolean';
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a value is an object.
|
|
164
|
+
*
|
|
165
|
+
* @param value - The value to check.
|
|
166
|
+
*
|
|
167
|
+
* @returns `true` if the value is an object; otherwise, `false`.
|
|
168
|
+
*/
|
|
81
169
|
const isObject = (value) => typeof value === 'object';
|
|
170
|
+
/**
|
|
171
|
+
* Checks if a value is an empty object (no own enumerable properties).
|
|
172
|
+
*
|
|
173
|
+
* @param value - The value to check.
|
|
174
|
+
*
|
|
175
|
+
* @returns `true` if the value is an empty object; otherwise, `false`.
|
|
176
|
+
*/
|
|
177
|
+
const isEmptyObject = (value) => isObject(value) && !isNull(value) && Object.keys(value).length === 0;
|
|
178
|
+
/**
|
|
179
|
+
* Checks if a value is an array.
|
|
180
|
+
*
|
|
181
|
+
* @param value - The value to check.
|
|
182
|
+
*
|
|
183
|
+
* @returns `true` if the value is an array; otherwise, `false`.
|
|
184
|
+
*/
|
|
185
|
+
const isArray = (value) => Array.isArray(value);
|
|
186
|
+
/**
|
|
187
|
+
* Checks if a value is an empty array.
|
|
188
|
+
*
|
|
189
|
+
* @param value - The value to check.
|
|
190
|
+
*
|
|
191
|
+
* @returns `true` if the value is an empty array; otherwise, `false`.
|
|
192
|
+
*/
|
|
193
|
+
const isEmptyArray = (value) => isArray(value) && value.length === 0;
|
|
194
|
+
/**
|
|
195
|
+
* Checks if a value is a function.
|
|
196
|
+
*
|
|
197
|
+
* @param value - The value to check.
|
|
198
|
+
*
|
|
199
|
+
* @returns `true` if the value is a function; otherwise, `false`.
|
|
200
|
+
*/
|
|
82
201
|
const isFunction = (value) => typeof value === 'function';
|
|
202
|
+
/**
|
|
203
|
+
* Checks if a value is a Promise.
|
|
204
|
+
*
|
|
205
|
+
* @template T - The type of the value that the Promise resolves to.
|
|
206
|
+
*
|
|
207
|
+
* @param value - The value to check.
|
|
208
|
+
*
|
|
209
|
+
* @returns `true` if the value is a Promise; otherwise, `false`.
|
|
210
|
+
*/
|
|
83
211
|
const isPromise = (value) => isFunction(value?.then);
|
|
84
212
|
/**
|
|
85
213
|
* Checks if a value is null or undefined.
|
|
@@ -102,6 +230,129 @@ const isNil = (value) => value === undefined || value === null;
|
|
|
102
230
|
* @returns `true` if the value is empty; otherwise, `false`.
|
|
103
231
|
*/
|
|
104
232
|
const isNilOrEmptyString = (value) => value === '' || isNil(value);
|
|
233
|
+
/**
|
|
234
|
+
* Checks if a value is a Date object.
|
|
235
|
+
*
|
|
236
|
+
* @param value - The value to check.
|
|
237
|
+
*
|
|
238
|
+
* @returns `true` if the value is a Date object; otherwise, `false`.
|
|
239
|
+
*/
|
|
240
|
+
const isDate = (value) => value instanceof Date;
|
|
241
|
+
/**
|
|
242
|
+
* Checks if a value is a valid Date object (not Invalid Date).
|
|
243
|
+
*
|
|
244
|
+
* @param value - The value to check.
|
|
245
|
+
*
|
|
246
|
+
* @returns `true` if the value is a valid Date object; otherwise, `false`.
|
|
247
|
+
*/
|
|
248
|
+
const isValidDate = (value) => isDate(value) && !isNaN(value.getTime());
|
|
249
|
+
/**
|
|
250
|
+
* Checks if a value is a RegExp object.
|
|
251
|
+
*
|
|
252
|
+
* @param value - The value to check.
|
|
253
|
+
*
|
|
254
|
+
* @returns `true` if the value is a RegExp object; otherwise, `false`.
|
|
255
|
+
*/
|
|
256
|
+
const isRegExp = (value) => value instanceof RegExp;
|
|
257
|
+
/**
|
|
258
|
+
* Checks if a value is a Map.
|
|
259
|
+
*
|
|
260
|
+
* @param value - The value to check.
|
|
261
|
+
*
|
|
262
|
+
* @returns `true` if the value is a Map; otherwise, `false`.
|
|
263
|
+
*/
|
|
264
|
+
const isMap = (value) => value instanceof Map;
|
|
265
|
+
/**
|
|
266
|
+
* Checks if a value is a Set.
|
|
267
|
+
*
|
|
268
|
+
* @param value - The value to check.
|
|
269
|
+
*
|
|
270
|
+
* @returns `true` if the value is a Set; otherwise, `false`.
|
|
271
|
+
*/
|
|
272
|
+
const isSet = (value) => value instanceof Set;
|
|
273
|
+
/**
|
|
274
|
+
* Checks if a value is a Symbol.
|
|
275
|
+
*
|
|
276
|
+
* @param value - The value to check.
|
|
277
|
+
*
|
|
278
|
+
* @returns `true` if the value is a Symbol; otherwise, `false`.
|
|
279
|
+
*/
|
|
280
|
+
const isSymbol = (value) => typeof value === 'symbol';
|
|
281
|
+
/**
|
|
282
|
+
* Checks if a value is undefined.
|
|
283
|
+
*
|
|
284
|
+
* @param value - The value to check.
|
|
285
|
+
*
|
|
286
|
+
* @returns `true` if the value is undefined; otherwise, `false`.
|
|
287
|
+
*/
|
|
288
|
+
const isUndefined = (value) => value === undefined;
|
|
289
|
+
/**
|
|
290
|
+
* Checks if a value is a finite number.
|
|
291
|
+
*
|
|
292
|
+
* @param value - The value to check.
|
|
293
|
+
*
|
|
294
|
+
* @returns `true` if the value is a finite number; otherwise, `false`.
|
|
295
|
+
*/
|
|
296
|
+
const isFiniteNumber = (value) => isNumber(value) && isFinite(value);
|
|
297
|
+
/**
|
|
298
|
+
* Checks if a value is an integer.
|
|
299
|
+
*
|
|
300
|
+
* @param value - The value to check.
|
|
301
|
+
*
|
|
302
|
+
* @returns `true` if the value is an integer; otherwise, `false`.
|
|
303
|
+
*/
|
|
304
|
+
const isInteger = (value) => isNumber(value) && Number.isInteger(value);
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
/***/ }),
|
|
308
|
+
|
|
309
|
+
/***/ "./src/math.ts":
|
|
310
|
+
/*!*********************!*\
|
|
311
|
+
!*** ./src/math.ts ***!
|
|
312
|
+
\*********************/
|
|
313
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
314
|
+
|
|
315
|
+
__webpack_require__.r(__webpack_exports__);
|
|
316
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
317
|
+
/* harmony export */ calculateEuclideanDistance: () => (/* binding */ calculateEuclideanDistance),
|
|
318
|
+
/* harmony export */ calculateMovingSpeed: () => (/* binding */ calculateMovingSpeed),
|
|
319
|
+
/* harmony export */ calculatePercentage: () => (/* binding */ calculatePercentage)
|
|
320
|
+
/* harmony export */ });
|
|
321
|
+
/**
|
|
322
|
+
* Calculates the Euclidean distance between two points in 2D space.
|
|
323
|
+
*
|
|
324
|
+
* @param startX - The X coordinate of the starting point.
|
|
325
|
+
* @param startY - The Y coordinate of the starting point.
|
|
326
|
+
* @param endX - The X coordinate of the ending point.
|
|
327
|
+
* @param endY - The Y coordinate of the ending point.
|
|
328
|
+
*
|
|
329
|
+
* @returns The Euclidean distance between the two points.
|
|
330
|
+
*/
|
|
331
|
+
const calculateEuclideanDistance = (startX, startY, endX, endY) => {
|
|
332
|
+
const deltaX = endX - startX;
|
|
333
|
+
const deltaY = endY - startY;
|
|
334
|
+
return Math.sqrt(deltaX ** 2 + deltaY ** 2);
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Calculates the moving speed.
|
|
338
|
+
*
|
|
339
|
+
* @param delta - The change in position (distance).
|
|
340
|
+
* @param elapsedTime - The time taken to move the distance.
|
|
341
|
+
*
|
|
342
|
+
* @returns The calculated speed, which is the absolute value of delta divided by elapsed time.
|
|
343
|
+
*/
|
|
344
|
+
const calculateMovingSpeed = (delta, elapsedTime) => Math.abs(delta / elapsedTime);
|
|
345
|
+
/**
|
|
346
|
+
* Calculates the specified percentage of a given value.
|
|
347
|
+
*
|
|
348
|
+
* @param value - The value to calculate the percentage of.
|
|
349
|
+
* @param percentage - The percentage to calculate.
|
|
350
|
+
*
|
|
351
|
+
* @returns The calculated percentage of the value.
|
|
352
|
+
*/
|
|
353
|
+
const calculatePercentage = (value, percentage) => {
|
|
354
|
+
return (value * percentage) / 100;
|
|
355
|
+
};
|
|
105
356
|
|
|
106
357
|
|
|
107
358
|
/***/ }),
|
|
@@ -114,10 +365,21 @@ const isNilOrEmptyString = (value) => value === '' || isNil(value);
|
|
|
114
365
|
|
|
115
366
|
__webpack_require__.r(__webpack_exports__);
|
|
116
367
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
368
|
+
/* harmony export */ camelToDashCase: () => (/* binding */ camelToDashCase),
|
|
117
369
|
/* harmony export */ hashString: () => (/* binding */ hashString),
|
|
370
|
+
/* harmony export */ splitStringIntoWords: () => (/* binding */ splitStringIntoWords),
|
|
118
371
|
/* harmony export */ toKebabCase: () => (/* binding */ toKebabCase)
|
|
119
372
|
/* harmony export */ });
|
|
120
|
-
const toKebabCase = (
|
|
373
|
+
const toKebabCase = (input) => input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
374
|
+
const camelToDashCase = (input) => input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
|
|
375
|
+
/**
|
|
376
|
+
* Splits a string into an array of filtered from redundant spaces words.
|
|
377
|
+
*
|
|
378
|
+
* @param input - The input string to be split.
|
|
379
|
+
*
|
|
380
|
+
* @returns An array of words from the input string.
|
|
381
|
+
*/
|
|
382
|
+
const splitStringIntoWords = (input) => input.split(' ').filter(Boolean);
|
|
121
383
|
/**
|
|
122
384
|
* Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.
|
|
123
385
|
*
|
|
@@ -132,7 +394,7 @@ const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerC
|
|
|
132
394
|
*
|
|
133
395
|
* ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.
|
|
134
396
|
*
|
|
135
|
-
* @param
|
|
397
|
+
* @param input - The input string to hash.
|
|
136
398
|
*
|
|
137
399
|
* @returns A short, base-36 encoded hash string.
|
|
138
400
|
*
|
|
@@ -142,10 +404,10 @@ const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerC
|
|
|
142
404
|
* // → 'e4k1z0x'
|
|
143
405
|
* ```
|
|
144
406
|
*/
|
|
145
|
-
const hashString = (
|
|
407
|
+
const hashString = (input) => {
|
|
146
408
|
let hash = 5381;
|
|
147
|
-
for (let i = 0; i <
|
|
148
|
-
hash = (hash * 33) ^
|
|
409
|
+
for (let i = 0; i < input.length; i++) {
|
|
410
|
+
hash = (hash * 33) ^ input.charCodeAt(i);
|
|
149
411
|
}
|
|
150
412
|
return (hash >>> 0).toString(36);
|
|
151
413
|
};
|
|
@@ -219,23 +481,46 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
219
481
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
220
482
|
/* harmony export */ assert: () => (/* binding */ assert),
|
|
221
483
|
/* harmony export */ boolFilter: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.boolFilter),
|
|
484
|
+
/* harmony export */ calculateEuclideanDistance: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculateEuclideanDistance),
|
|
485
|
+
/* harmony export */ calculateMovingSpeed: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculateMovingSpeed),
|
|
486
|
+
/* harmony export */ calculatePercentage: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculatePercentage),
|
|
487
|
+
/* harmony export */ camelToDashCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.camelToDashCase),
|
|
488
|
+
/* harmony export */ getTransformationValues: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_5__.getTransformationValues),
|
|
222
489
|
/* harmony export */ hashString: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.hashString),
|
|
223
490
|
/* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.invokeIfFunction),
|
|
491
|
+
/* harmony export */ isArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isArray),
|
|
224
492
|
/* harmony export */ isBool: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isBool),
|
|
493
|
+
/* harmony export */ isDate: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isDate),
|
|
494
|
+
/* harmony export */ isEmptyArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isEmptyArray),
|
|
495
|
+
/* harmony export */ isEmptyObject: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isEmptyObject),
|
|
496
|
+
/* harmony export */ isFiniteNumber: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isFiniteNumber),
|
|
225
497
|
/* harmony export */ isFunction: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isFunction),
|
|
498
|
+
/* harmony export */ isInteger: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isInteger),
|
|
499
|
+
/* harmony export */ isMap: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isMap),
|
|
226
500
|
/* harmony export */ isNil: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isNil),
|
|
227
501
|
/* harmony export */ isNilOrEmptyString: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isNilOrEmptyString),
|
|
502
|
+
/* harmony export */ isNull: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isNull),
|
|
228
503
|
/* harmony export */ isNumber: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isNumber),
|
|
229
504
|
/* harmony export */ isObject: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isObject),
|
|
230
505
|
/* harmony export */ isPromise: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isPromise),
|
|
506
|
+
/* harmony export */ isRegExp: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isRegExp),
|
|
507
|
+
/* harmony export */ isSet: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isSet),
|
|
231
508
|
/* harmony export */ isString: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isString),
|
|
509
|
+
/* harmony export */ isSymbol: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isSymbol),
|
|
510
|
+
/* harmony export */ isUndefined: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isUndefined),
|
|
511
|
+
/* harmony export */ isValidDate: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isValidDate),
|
|
232
512
|
/* harmony export */ noop: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.noop),
|
|
513
|
+
/* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.splitStringIntoWords),
|
|
233
514
|
/* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.toKebabCase)
|
|
234
515
|
/* harmony export */ });
|
|
235
516
|
/* harmony import */ var _string__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./string */ "./src/string.ts");
|
|
236
517
|
/* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array */ "./src/array.ts");
|
|
237
518
|
/* harmony import */ var _function__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./function */ "./src/function.ts");
|
|
238
519
|
/* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./guards */ "./src/guards.ts");
|
|
520
|
+
/* harmony import */ var _math__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./math */ "./src/math.ts");
|
|
521
|
+
/* harmony import */ var _dom__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./dom */ "./src/dom.ts");
|
|
522
|
+
|
|
523
|
+
|
|
239
524
|
|
|
240
525
|
|
|
241
526
|
|