@herowcode/utils 1.0.1

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.
Files changed (112) hide show
  1. package/README.md +224 -0
  2. package/dist/array/index.d.ts +3 -0
  3. package/dist/array/index.d.ts.map +1 -0
  4. package/dist/array/index.esm.js +2 -0
  5. package/dist/array/index.js +2 -0
  6. package/dist/array/index.js.map +1 -0
  7. package/dist/array/shuffle.d.ts +2 -0
  8. package/dist/array/shuffle.d.ts.map +1 -0
  9. package/dist/array/shuffle.esm.js +12 -0
  10. package/dist/array/shuffle.js +12 -0
  11. package/dist/array/shuffle.js.map +1 -0
  12. package/dist/array/unique.d.ts +2 -0
  13. package/dist/array/unique.d.ts.map +1 -0
  14. package/dist/array/unique.esm.js +3 -0
  15. package/dist/array/unique.js +3 -0
  16. package/dist/array/unique.js.map +1 -0
  17. package/dist/date/dayjs.d.ts +3 -0
  18. package/dist/date/dayjs.d.ts.map +1 -0
  19. package/dist/date/dayjs.esm.js +14 -0
  20. package/dist/date/dayjs.js +14 -0
  21. package/dist/date/dayjs.js.map +1 -0
  22. package/dist/date/fixTimezoneOffset.d.ts +3 -0
  23. package/dist/date/fixTimezoneOffset.d.ts.map +1 -0
  24. package/dist/date/fixTimezoneOffset.esm.js +5 -0
  25. package/dist/date/fixTimezoneOffset.js +5 -0
  26. package/dist/date/fixTimezoneOffset.js.map +1 -0
  27. package/dist/date/formatDate.d.ts +2 -0
  28. package/dist/date/formatDate.d.ts.map +1 -0
  29. package/dist/date/formatDate.esm.js +9 -0
  30. package/dist/date/formatDate.js +9 -0
  31. package/dist/date/formatDate.js.map +1 -0
  32. package/dist/date/getCurrentDateInUTC.d.ts +3 -0
  33. package/dist/date/getCurrentDateInUTC.d.ts.map +1 -0
  34. package/dist/date/getCurrentDateInUTC.esm.js +4 -0
  35. package/dist/date/getCurrentDateInUTC.js +4 -0
  36. package/dist/date/getCurrentDateInUTC.js.map +1 -0
  37. package/dist/date/getDateInUTC.d.ts +3 -0
  38. package/dist/date/getDateInUTC.d.ts.map +1 -0
  39. package/dist/date/getDateInUTC.esm.js +4 -0
  40. package/dist/date/getDateInUTC.js +4 -0
  41. package/dist/date/getDateInUTC.js.map +1 -0
  42. package/dist/date/index.d.ts +7 -0
  43. package/dist/date/index.d.ts.map +1 -0
  44. package/dist/date/index.esm.js +6 -0
  45. package/dist/date/index.js +6 -0
  46. package/dist/date/index.js.map +1 -0
  47. package/dist/date/parseTimeSpent.d.ts +2 -0
  48. package/dist/date/parseTimeSpent.d.ts.map +1 -0
  49. package/dist/date/parseTimeSpent.esm.js +85 -0
  50. package/dist/date/parseTimeSpent.js +85 -0
  51. package/dist/date/parseTimeSpent.js.map +1 -0
  52. package/dist/function.d.ts +18 -0
  53. package/dist/function.d.ts.map +1 -0
  54. package/dist/function.esm.js +54 -0
  55. package/dist/function.js +54 -0
  56. package/dist/function.js.map +1 -0
  57. package/dist/index.d.ts +6 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.esm.js +10 -0
  60. package/dist/index.js +10 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/number.d.ts +8 -0
  63. package/dist/number.d.ts.map +1 -0
  64. package/dist/number.esm.js +15 -0
  65. package/dist/number.js +15 -0
  66. package/dist/number.js.map +1 -0
  67. package/dist/string/camel-case.d.ts +2 -0
  68. package/dist/string/camel-case.d.ts.map +1 -0
  69. package/dist/string/camel-case.esm.js +21 -0
  70. package/dist/string/camel-case.js +21 -0
  71. package/dist/string/camel-case.js.map +1 -0
  72. package/dist/string/capitalize.d.ts +2 -0
  73. package/dist/string/capitalize.d.ts.map +1 -0
  74. package/dist/string/capitalize.esm.js +9 -0
  75. package/dist/string/capitalize.js +9 -0
  76. package/dist/string/capitalize.js.map +1 -0
  77. package/dist/string/index.d.ts +9 -0
  78. package/dist/string/index.d.ts.map +1 -0
  79. package/dist/string/index.esm.js +8 -0
  80. package/dist/string/index.js +8 -0
  81. package/dist/string/index.js.map +1 -0
  82. package/dist/string/kebab-case.d.ts +2 -0
  83. package/dist/string/kebab-case.d.ts.map +1 -0
  84. package/dist/string/kebab-case.esm.js +11 -0
  85. package/dist/string/kebab-case.js +11 -0
  86. package/dist/string/kebab-case.js.map +1 -0
  87. package/dist/string/remove-html-tags.d.ts +2 -0
  88. package/dist/string/remove-html-tags.d.ts.map +1 -0
  89. package/dist/string/remove-html-tags.esm.js +14 -0
  90. package/dist/string/remove-html-tags.js +14 -0
  91. package/dist/string/remove-html-tags.js.map +1 -0
  92. package/dist/string/slugify.d.ts +2 -0
  93. package/dist/string/slugify.d.ts.map +1 -0
  94. package/dist/string/slugify.esm.js +9 -0
  95. package/dist/string/slugify.js +9 -0
  96. package/dist/string/slugify.js.map +1 -0
  97. package/dist/string/snake-case.d.ts +2 -0
  98. package/dist/string/snake-case.d.ts.map +1 -0
  99. package/dist/string/snake-case.esm.js +11 -0
  100. package/dist/string/snake-case.js +11 -0
  101. package/dist/string/snake-case.js.map +1 -0
  102. package/dist/string/to-sentence-case.d.ts +2 -0
  103. package/dist/string/to-sentence-case.d.ts.map +1 -0
  104. package/dist/string/to-sentence-case.esm.js +9 -0
  105. package/dist/string/to-sentence-case.js +9 -0
  106. package/dist/string/to-sentence-case.js.map +1 -0
  107. package/dist/string/truncate.d.ts +2 -0
  108. package/dist/string/truncate.d.ts.map +1 -0
  109. package/dist/string/truncate.esm.js +15 -0
  110. package/dist/string/truncate.js +15 -0
  111. package/dist/string/truncate.js.map +1 -0
  112. package/package.json +92 -0
@@ -0,0 +1,85 @@
1
+ import { fixTimezoneOffset } from "./fixTimezoneOffset";
2
+ // Supported locales and their translations
3
+ const locales = {
4
+ "pt-BR": {
5
+ year: { singular: "ano", plural: "anos" },
6
+ month: { singular: "mês", plural: "meses" },
7
+ day: { singular: "dia", plural: "dias" },
8
+ formatList: (parts) => {
9
+ if (parts.length === 0)
10
+ return "";
11
+ if (parts.length === 1)
12
+ return parts[0];
13
+ const lastPart = parts[parts.length - 1];
14
+ const otherParts = parts.slice(0, -1);
15
+ return `${otherParts.join(", ")} e ${lastPart}`;
16
+ },
17
+ },
18
+ "en-US": {
19
+ year: { singular: "year", plural: "years" },
20
+ month: { singular: "month", plural: "months" },
21
+ day: { singular: "day", plural: "days" },
22
+ formatList: (parts) => {
23
+ if (parts.length === 0)
24
+ return "";
25
+ if (parts.length === 1)
26
+ return parts[0];
27
+ if (parts.length === 2)
28
+ return `${parts[0]} and ${parts[1]}`;
29
+ return `${parts.slice(0, -1).join(", ")}, and ${parts[parts.length - 1]}`;
30
+ },
31
+ },
32
+ "es-ES": {
33
+ year: { singular: "año", plural: "años" },
34
+ month: { singular: "mes", plural: "meses" },
35
+ day: { singular: "día", plural: "días" },
36
+ formatList: (parts) => {
37
+ if (parts.length === 0)
38
+ return "";
39
+ if (parts.length === 1)
40
+ return parts[0];
41
+ const lastPart = parts[parts.length - 1];
42
+ const otherParts = parts.slice(0, -1);
43
+ return `${otherParts.join(", ")} y ${lastPart}`;
44
+ },
45
+ },
46
+ "fr-FR": {
47
+ year: { singular: "an", plural: "ans" },
48
+ month: { singular: "mois", plural: "mois" },
49
+ day: { singular: "jour", plural: "jours" },
50
+ formatList: (parts) => {
51
+ if (parts.length === 0)
52
+ return "";
53
+ if (parts.length === 1)
54
+ return parts[0];
55
+ const lastPart = parts[parts.length - 1];
56
+ const otherParts = parts.slice(0, -1);
57
+ return `${otherParts.join(", ")} et ${lastPart}`;
58
+ },
59
+ },
60
+ };
61
+ export function parseTimeSpent(initialDate, finalDate, locale = "pt-BR") {
62
+ const final = fixTimezoneOffset(finalDate);
63
+ const initial = fixTimezoneOffset(initialDate);
64
+ const years = final.diff(initial, "year");
65
+ const months = final.diff(initial.add(years, "year"), "month");
66
+ const days = final.diff(initial.add(years, "year").add(months, "month"), "day");
67
+ // Use default locale if the requested one isn't supported
68
+ const translations = locales[locale] || locales["pt-BR"];
69
+ // Format each time unit
70
+ const parts = [];
71
+ if (years > 0) {
72
+ const unit = years === 1 ? translations.year.singular : translations.year.plural;
73
+ parts.push(`${years} ${unit}`);
74
+ }
75
+ if (months > 0) {
76
+ const unit = months === 1 ? translations.month.singular : translations.month.plural;
77
+ parts.push(`${months} ${unit}`);
78
+ }
79
+ if (days > 0) {
80
+ const unit = days === 1 ? translations.day.singular : translations.day.plural;
81
+ parts.push(`${days} ${unit}`);
82
+ }
83
+ // Format according to locale's list formatting rules
84
+ return translations.formatList(parts);
85
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseTimeSpent.js","sourceRoot":"","sources":["../../src/date/parseTimeSpent.ts"],"names":[],"mappings":";;AA4DA,wCAyCC;AArGD,2DAAuD;AASvD,2CAA2C;AAC3C,MAAM,OAAO,GAAwC;IACnD,OAAO,EAAE;QACP,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QACzC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE;QAC3C,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QACxC,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;YACpB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAE,CAAA;YACjC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;YACvC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YACxC,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACrC,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,QAAQ,EAAE,CAAA;QACjD,CAAC;KACF;IACD,OAAO,EAAE;QACP,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;QAC3C,KAAK,E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;
2
+ /**
3
+ * Creates a debounced function that delays invoking func until after delay milliseconds
4
+ * have elapsed since the last time the debounced function was invoked
5
+ * @param fn - The function to debounce
6
+ * @param delay - The number of milliseconds to delay
7
+ * @returns The debounced function
8
+ */
9
+ export declare function debounce<T extends TAnyFunction>(fn: T, delay: number): (...args: Parameters<T>) => void;
10
+ /**
11
+ * Creates a throttled function that only invokes func at most once per every delay milliseconds
12
+ * @param fn - The function to throttle
13
+ * @param delay - The number of milliseconds to throttle invocations to
14
+ * @returns The throttled function
15
+ */
16
+ export declare function throttle<T extends TAnyFunction>(fn: T, delay: number): (...args: Parameters<T>) => void;
17
+ export {};
18
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAA;AAEnD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,YAAY,EAC7C,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAiBlC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,YAAY,EAC7C,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CA+BlC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Creates a debounced function that delays invoking func until after delay milliseconds
3
+ * have elapsed since the last time the debounced function was invoked
4
+ * @param fn - The function to debounce
5
+ * @param delay - The number of milliseconds to delay
6
+ * @returns The debounced function
7
+ */
8
+ export function debounce(fn, delay) {
9
+ if (typeof fn !== "function") {
10
+ throw new Error("First argument must be a function");
11
+ }
12
+ if (typeof delay !== "number" || delay < 0) {
13
+ throw new Error("Delay must be a non-negative number");
14
+ }
15
+ let timeoutId;
16
+ return function (...args) {
17
+ if (timeoutId) {
18
+ clearTimeout(timeoutId);
19
+ }
20
+ timeoutId = setTimeout(() => fn.apply(this, args), delay);
21
+ };
22
+ }
23
+ /**
24
+ * Creates a throttled function that only invokes func at most once per every delay milliseconds
25
+ * @param fn - The function to throttle
26
+ * @param delay - The number of milliseconds to throttle invocations to
27
+ * @returns The throttled function
28
+ */
29
+ export function throttle(fn, delay) {
30
+ if (typeof fn !== "function") {
31
+ throw new Error("First argument must be a function");
32
+ }
33
+ if (typeof delay !== "number" || delay < 0) {
34
+ throw new Error("Delay must be a non-negative number");
35
+ }
36
+ let lastCall = 0;
37
+ let timeoutId;
38
+ return function (...args) {
39
+ const now = Date.now();
40
+ if (now - lastCall >= delay) {
41
+ lastCall = now;
42
+ fn.apply(this, args);
43
+ }
44
+ else {
45
+ if (timeoutId) {
46
+ clearTimeout(timeoutId);
47
+ }
48
+ timeoutId = setTimeout(() => {
49
+ lastCall = Date.now();
50
+ fn.apply(this, args);
51
+ }, delay - (now - lastCall));
52
+ }
53
+ };
54
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Creates a debounced function that delays invoking func until after delay milliseconds
3
+ * have elapsed since the last time the debounced function was invoked
4
+ * @param fn - The function to debounce
5
+ * @param delay - The number of milliseconds to delay
6
+ * @returns The debounced function
7
+ */
8
+ export function debounce(fn, delay) {
9
+ if (typeof fn !== "function") {
10
+ throw new Error("First argument must be a function");
11
+ }
12
+ if (typeof delay !== "number" || delay < 0) {
13
+ throw new Error("Delay must be a non-negative number");
14
+ }
15
+ let timeoutId;
16
+ return function (...args) {
17
+ if (timeoutId) {
18
+ clearTimeout(timeoutId);
19
+ }
20
+ timeoutId = setTimeout(() => fn.apply(this, args), delay);
21
+ };
22
+ }
23
+ /**
24
+ * Creates a throttled function that only invokes func at most once per every delay milliseconds
25
+ * @param fn - The function to throttle
26
+ * @param delay - The number of milliseconds to throttle invocations to
27
+ * @returns The throttled function
28
+ */
29
+ export function throttle(fn, delay) {
30
+ if (typeof fn !== "function") {
31
+ throw new Error("First argument must be a function");
32
+ }
33
+ if (typeof delay !== "number" || delay < 0) {
34
+ throw new Error("Delay must be a non-negative number");
35
+ }
36
+ let lastCall = 0;
37
+ let timeoutId;
38
+ return function (...args) {
39
+ const now = Date.now();
40
+ if (now - lastCall >= delay) {
41
+ lastCall = now;
42
+ fn.apply(this, args);
43
+ }
44
+ else {
45
+ if (timeoutId) {
46
+ clearTimeout(timeoutId);
47
+ }
48
+ timeoutId = setTimeout(() => {
49
+ lastCall = Date.now();
50
+ fn.apply(this, args);
51
+ }, delay - (now - lastCall));
52
+ }
53
+ };
54
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":";;AASA,4BAoBC;AAQD,4BAkCC;AArED;;;;;;GAMG;AACH,SAAgB,QAAQ,CACtB,EAAK,EACL,KAAa;IAEb,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IAED,IAAI,SAAoD,CAAA;IAExD,OAAO,UAAyB,GAAG,IAAmB;QACpD,IAAI,SAAS,EAAE,CAAC;YACd,YAAY,CAAC,SAAS,CAAC,CAAA;QACzB,CAAC;QACD,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAA;IAC3D,CAAC,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CACtB,EAAK,EACL,KAAa;IAEb,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IAED,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,SAAoD,CAAA;IAExD,OAAO,UAAyB,GAAG,IAAmB;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEtB,IAAI,GAAG,GAAG,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC5B,QAAQ,GAAG,GAAG,CAAA;YACd,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACtB,CAAC;aAAM,CAAC;YACN,IAAI,SAAS,EAAE,CAAC;gBACd,YAAY,CAAC,SAAS,CAAC,CAAA;YACzB,CAAC;YACD,SAAS,GAAG,UAAU,CACpB,GAAG,EAAE;gBACH,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;gBACrB,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YACtB,CAAC,EACD,KAAK,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,CACzB,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./array/index.js";
2
+ export * from "./date/index.js";
3
+ export { debounce, throttle } from "./function.js";
4
+ export { randomInt } from "./number.js";
5
+ export * from "./string/index.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,10 @@
1
+ // Date utilities
2
+ // Array utilities
3
+ export * from "./array/index.js";
4
+ export * from "./date/index.js";
5
+ // Function utilities
6
+ export { debounce, throttle } from "./function.js";
7
+ // Number utilities
8
+ export { randomInt } from "./number.js";
9
+ // String utilities
10
+ export * from "./string/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // Date utilities
2
+ // Array utilities
3
+ export * from "./array/index.js";
4
+ export * from "./date/index.js";
5
+ // Function utilities
6
+ export { debounce, throttle } from "./function.js";
7
+ // Number utilities
8
+ export { randomInt } from "./number.js";
9
+ // String utilities
10
+ export * from "./string/index.js";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iBAAiB;;;;;;;;;;;;;;;;;AAEjB,kBAAkB;AAClB,mDAAgC;AAChC,kDAA+B;AAC/B,qBAAqB;AACrB,6CAAkD;AAAzC,uGAAA,QAAQ,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAC3B,mBAAmB;AACnB,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,mBAAmB;AACnB,oDAAiC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates a random integer between min and max (inclusive)
3
+ * @param min - The minimum value (inclusive)
4
+ * @param max - The maximum value (inclusive)
5
+ * @returns A random integer between min and max
6
+ */
7
+ export declare function randomInt(min: number, max: number): number;
8
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAU1D"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Generates a random integer between min and max (inclusive)
3
+ * @param min - The minimum value (inclusive)
4
+ * @param max - The maximum value (inclusive)
5
+ * @returns A random integer between min and max
6
+ */
7
+ export function randomInt(min, max) {
8
+ if (!Number.isInteger(min) || !Number.isInteger(max)) {
9
+ throw new Error("Both min and max must be integers");
10
+ }
11
+ if (min > max) {
12
+ throw new Error("Min value cannot be greater than max value");
13
+ }
14
+ return Math.floor(Math.random() * (max - min + 1)) + min;
15
+ }
package/dist/number.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Generates a random integer between min and max (inclusive)
3
+ * @param min - The minimum value (inclusive)
4
+ * @param max - The maximum value (inclusive)
5
+ * @returns A random integer between min and max
6
+ */
7
+ export function randomInt(min, max) {
8
+ if (!Number.isInteger(min) || !Number.isInteger(max)) {
9
+ throw new Error("Both min and max must be integers");
10
+ }
11
+ if (min > max) {
12
+ throw new Error("Min value cannot be greater than max value");
13
+ }
14
+ return Math.floor(Math.random() * (max - min + 1)) + min;
15
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":";;AAMA,8BAUC;AAhBD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;AAC1D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function camelCase(str: string): string;
2
+ //# sourceMappingURL=camel-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camel-case.d.ts","sourceRoot":"","sources":["../../src/string/camel-case.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA0B7C"}
@@ -0,0 +1,21 @@
1
+ export function camelCase(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ if (str.length === 0) {
6
+ return str;
7
+ }
8
+ const words = str
9
+ .toLowerCase()
10
+ .replace(/[^a-zA-Z0-9\s\-_]/g, "")
11
+ .split(/[\s\-_]+/)
12
+ .filter((word) => word.length > 0);
13
+ if (words.length === 0) {
14
+ return "";
15
+ }
16
+ return (words[0] +
17
+ words
18
+ .slice(1)
19
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
20
+ .join(""));
21
+ }
@@ -0,0 +1,21 @@
1
+ export function camelCase(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ if (str.length === 0) {
6
+ return str;
7
+ }
8
+ const words = str
9
+ .toLowerCase()
10
+ .replace(/[^a-zA-Z0-9\s\-_]/g, "")
11
+ .split(/[\s\-_]+/)
12
+ .filter((word) => word.length > 0);
13
+ if (words.length === 0) {
14
+ return "";
15
+ }
16
+ return (words[0] +
17
+ words
18
+ .slice(1)
19
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
20
+ .join(""));
21
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camel-case.js","sourceRoot":"","sources":["../../src/string/camel-case.ts"],"names":[],"mappings":";;AAAA,8BA0BC;AA1BD,SAAgB,SAAS,CAAC,GAAW;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,GAAG;SACd,WAAW,EAAE;SACb,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;SACjC,KAAK,CAAC,UAAU,CAAC;SACjB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO,CACL,KAAK,CAAC,CAAC,CAAC;QACR,KAAK;aACF,KAAK,CAAC,CAAC,CAAC;aACR,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAC3D,IAAI,CAAC,EAAE,CAAC,CACZ,CAAA;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function capitalize(str: string): string;
2
+ //# sourceMappingURL=capitalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../../src/string/capitalize.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU9C"}
@@ -0,0 +1,9 @@
1
+ export function capitalize(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ if (str.length === 0) {
6
+ return str;
7
+ }
8
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
9
+ }
@@ -0,0 +1,9 @@
1
+ export function capitalize(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ if (str.length === 0) {
6
+ return str;
7
+ }
8
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
9
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capitalize.js","sourceRoot":"","sources":["../../src/string/capitalize.ts"],"names":[],"mappings":";;AAAA,gCAUC;AAVD,SAAgB,UAAU,CAAC,GAAW;IACpC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;AACjE,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from "./camel-case";
2
+ export * from "./capitalize";
3
+ export * from "./kebab-case";
4
+ export * from "./remove-html-tags";
5
+ export * from "./slugify";
6
+ export * from "./snake-case";
7
+ export * from "./to-sentence-case";
8
+ export * from "./truncate";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,8 @@
1
+ export * from "./camel-case";
2
+ export * from "./capitalize";
3
+ export * from "./kebab-case";
4
+ export * from "./remove-html-tags";
5
+ export * from "./slugify";
6
+ export * from "./snake-case";
7
+ export * from "./to-sentence-case";
8
+ export * from "./truncate";
@@ -0,0 +1,8 @@
1
+ export * from "./camel-case";
2
+ export * from "./capitalize";
3
+ export * from "./kebab-case";
4
+ export * from "./remove-html-tags";
5
+ export * from "./slugify";
6
+ export * from "./snake-case";
7
+ export * from "./to-sentence-case";
8
+ export * from "./truncate";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,+CAA4B;AAC5B,+CAA4B;AAC5B,qDAAkC;AAClC,4CAAyB;AACzB,+CAA4B;AAC5B,qDAAkC;AAClC,6CAA0B"}
@@ -0,0 +1,2 @@
1
+ export declare function kebabCase(str: string): string;
2
+ //# sourceMappingURL=kebab-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kebab-case.d.ts","sourceRoot":"","sources":["../../src/string/kebab-case.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAW7C"}
@@ -0,0 +1,11 @@
1
+ export function kebabCase(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ return str
6
+ .replace(/([a-z])([A-Z])/g, "$1-$2")
7
+ .replace(/[\s_]+/g, "-")
8
+ .replace(/[^a-zA-Z0-9-]/g, "")
9
+ .toLowerCase()
10
+ .replace(/^-+|-+$/g, "");
11
+ }
@@ -0,0 +1,11 @@
1
+ export function kebabCase(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ return str
6
+ .replace(/([a-z])([A-Z])/g, "$1-$2")
7
+ .replace(/[\s_]+/g, "-")
8
+ .replace(/[^a-zA-Z0-9-]/g, "")
9
+ .toLowerCase()
10
+ .replace(/^-+|-+$/g, "");
11
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kebab-case.js","sourceRoot":"","sources":["../../src/string/kebab-case.ts"],"names":[],"mappings":";;AAAA,8BAWC;AAXD,SAAgB,SAAS,CAAC,GAAW;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC3C,CAAC;IAED,OAAO,GAAG;SACP,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;SACnC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,WAAW,EAAE;SACb,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function removeHtmlTags(input: string): string;
2
+ //# sourceMappingURL=remove-html-tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-html-tags.d.ts","sourceRoot":"","sources":["../../src/string/remove-html-tags.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAepD"}
@@ -0,0 +1,14 @@
1
+ export function removeHtmlTags(input) {
2
+ // Input validation
3
+ if (!input || typeof input !== "string") {
4
+ return "";
5
+ }
6
+ // Apply reasonable input length limit for safety
7
+ const maxLength = 100000; // Adjust based on your requirements
8
+ let updatedInput = input;
9
+ if (updatedInput.length > maxLength) {
10
+ updatedInput = updatedInput.slice(0, maxLength);
11
+ }
12
+ // Use a non-backtracking approach to prevent ReDoS vulnerabilities
13
+ return updatedInput.replace(/<(?:[^>"']|"[^"]*"|'[^']*')*>/g, "");
14
+ }
@@ -0,0 +1,14 @@
1
+ export function removeHtmlTags(input) {
2
+ // Input validation
3
+ if (!input || typeof input !== "string") {
4
+ return "";
5
+ }
6
+ // Apply reasonable input length limit for safety
7
+ const maxLength = 100000; // Adjust based on your requirements
8
+ let updatedInput = input;
9
+ if (updatedInput.length > maxLength) {
10
+ updatedInput = updatedInput.slice(0, maxLength);
11
+ }
12
+ // Use a non-backtracking approach to prevent ReDoS vulnerabilities
13
+ return updatedInput.replace(/<(?:[^>"']|"[^"]*"|'[^']*')*>/g, "");
14
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-html-tags.js","sourceRoot":"","sources":["../../src/string/remove-html-tags.ts"],"names":[],"mappings":";;AAAA,wCAeC;AAfD,SAAgB,cAAc,CAAC,KAAa;IAC1C,mBAAmB;IACnB,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,CAAA;IACX,CAAC;IAED,iDAAiD;IACjD,MAAM,SAAS,GAAG,MAAM,CAAA,CAAC,oCAAoC;IAC7D,IAAI,YAAY,GAAG,KAAK,CAAA;IACxB,IAAI,YAAY,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QACpC,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;IACjD,CAAC;IAED,mEAAmE;IACnE,OAAO,YAAY,CAAC,OAAO,CAAC,gCAAgC,EAAE,EAAE,CAAC,CAAA;AACnE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function slugify(text: string): string;
2
+ //# sourceMappingURL=slugify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugify.d.ts","sourceRoot":"","sources":["../../src/string/slugify.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5C"}
@@ -0,0 +1,9 @@
1
+ export function slugify(text) {
2
+ return text
3
+ .normalize("NFD")
4
+ .replace(/[\u0300-\u036f]/g, "")
5
+ .replace(/[^\w\s]/gi, "")
6
+ .trim()
7
+ .replace(/\s+/g, "-")
8
+ .toLowerCase();
9
+ }
@@ -0,0 +1,9 @@
1
+ export function slugify(text) {
2
+ return text
3
+ .normalize("NFD")
4
+ .replace(/[\u0300-\u036f]/g, "")
5
+ .replace(/[^\w\s]/gi, "")
6
+ .trim()
7
+ .replace(/\s+/g, "-")
8
+ .toLowerCase();
9
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slugify.js","sourceRoot":"","sources":["../../src/string/slugify.ts"],"names":[],"mappings":";;AAAA,0BAQC;AARD,SAAgB,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI;SACR,SAAS,CAAC,KAAK,CAAC;SAChB,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;SAC/B,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,IAAI,EAAE;SACN,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,WAAW,EAAE,CAAA;AAClB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function snakeCase(str: string): string;
2
+ //# sourceMappingURL=snake-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snake-case.d.ts","sourceRoot":"","sources":["../../src/string/snake-case.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAW7C"}
@@ -0,0 +1,11 @@
1
+ export function snakeCase(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ return str
6
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
7
+ .replace(/[\s-]+/g, "_")
8
+ .replace(/[^a-zA-Z0-9_]/g, "")
9
+ .toLowerCase()
10
+ .replace(/^_+|_+$/g, "");
11
+ }
@@ -0,0 +1,11 @@
1
+ export function snakeCase(str) {
2
+ if (typeof str !== "string") {
3
+ throw new Error("Input must be a string");
4
+ }
5
+ return str
6
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
7
+ .replace(/[\s-]+/g, "_")
8
+ .replace(/[^a-zA-Z0-9_]/g, "")
9
+ .toLowerCase()
10
+ .replace(/^_+|_+$/g, "");
11
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snake-case.js","sourceRoot":"","sources":["../../src/string/snake-case.ts"],"names":[],"mappings":";;AAAA,8BAWC;AAXD,SAAgB,SAAS,CAAC,GAAW;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC3C,CAAC;IAED,OAAO,GAAG;SACP,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;SACnC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,WAAW,EAAE;SACb,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function toSentenceCase(str: string): string;
2
+ //# sourceMappingURL=to-sentence-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-sentence-case.d.ts","sourceRoot":"","sources":["../../src/string/to-sentence-case.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,UAQzC"}
@@ -0,0 +1,9 @@
1
+ export function toSentenceCase(str) {
2
+ return str
3
+ .replace(/_/g, " ")
4
+ .replace(/([A-Z])/g, " $1")
5
+ .toLowerCase()
6
+ .replace(/^\w/, (c) => c.toUpperCase())
7
+ .replace(/\s+/g, " ")
8
+ .trim();
9
+ }