@nemigo/helpers 2.8.1 → 2.8.3

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/string.d.ts CHANGED
@@ -101,3 +101,7 @@ export declare const toCapitalCaseMap: (str?: string) => string;
101
101
  * ```
102
102
  */
103
103
  export declare const repeat: (str: string, length: number, separator?: string) => string;
104
+ /**
105
+ * Создает на основе строки UUID по DJB2
106
+ */
107
+ export declare const toUUID: (key: string) => string;
package/dist/string.js CHANGED
@@ -101,3 +101,13 @@ export const toCapitalCaseMap = (str = "") => str.split(" ").map(toCapitalCase).
101
101
  * ```
102
102
  */
103
103
  export const repeat = (str, length, separator = "") => Array.from({ length }).fill(str).join(separator);
104
+ /**
105
+ * Создает на основе строки UUID по DJB2
106
+ */
107
+ export const toUUID = (key) => {
108
+ let hash = 5381; // DJB2
109
+ for (let i = 0; i < key.length; i++)
110
+ hash = ((hash << 5) + hash) ^ (key.codePointAt(i) ?? 0);
111
+ const hex = Math.trunc(hash).toString(16).padStart(8, "0");
112
+ return `${hex}-0000-0000-0000-000000000000`;
113
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
4
4
  "private": false,
5
5
  "license": "MPL-2.0",
6
6
  "author": {