@develia/commons 0.4.9 → 0.4.12

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 (89) hide show
  1. package/dist/cjs/array.js +5 -4
  2. package/dist/cjs/array.js.map +1 -1
  3. package/dist/cjs/browser/form-utilities.js +29 -23
  4. package/dist/cjs/browser/form-utilities.js.map +1 -1
  5. package/dist/cjs/browser/geo-location.js +61 -37
  6. package/dist/cjs/browser/geo-location.js.map +1 -1
  7. package/dist/cjs/browser/index.js +46 -1
  8. package/dist/cjs/browser/index.js.map +1 -1
  9. package/dist/cjs/event-bus.js +70 -0
  10. package/dist/cjs/event-bus.js.map +1 -0
  11. package/dist/cjs/from.js +1 -1
  12. package/dist/cjs/from.js.map +1 -1
  13. package/dist/cjs/index.js +4 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/math.js +3 -2
  16. package/dist/cjs/math.js.map +1 -1
  17. package/dist/cjs/parse.js +4 -3
  18. package/dist/cjs/parse.js.map +1 -1
  19. package/dist/cjs/patch.js +3 -2
  20. package/dist/cjs/patch.js.map +1 -1
  21. package/dist/cjs/string.js +43 -3
  22. package/dist/cjs/string.js.map +1 -1
  23. package/dist/cjs/utilities.js +25 -24
  24. package/dist/cjs/utilities.js.map +1 -1
  25. package/dist/esm/browser/form-utilities.js +23 -18
  26. package/dist/esm/browser/form-utilities.js.map +1 -1
  27. package/dist/esm/browser/geo-location.js +60 -36
  28. package/dist/esm/browser/geo-location.js.map +1 -1
  29. package/dist/esm/browser/index.js +44 -0
  30. package/dist/esm/browser/index.js.map +1 -1
  31. package/dist/esm/event-bus.js +65 -0
  32. package/dist/esm/event-bus.js.map +1 -0
  33. package/dist/esm/index.js +1 -0
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/string.js +34 -0
  36. package/dist/esm/string.js.map +1 -1
  37. package/dist/types/browser/form-utilities.d.ts +2 -2
  38. package/dist/types/browser/form-utilities.d.ts.map +1 -1
  39. package/dist/types/browser/geo-location.d.ts.map +1 -1
  40. package/dist/types/browser/index.d.ts +7 -0
  41. package/dist/types/browser/index.d.ts.map +1 -1
  42. package/dist/types/event-bus.d.ts +21 -0
  43. package/dist/types/event-bus.d.ts.map +1 -0
  44. package/dist/types/index.d.ts +1 -0
  45. package/dist/types/index.d.ts.map +1 -1
  46. package/dist/types/string.d.ts +5 -0
  47. package/dist/types/string.d.ts.map +1 -1
  48. package/dist/web/browser/form-utilities.js +23 -18
  49. package/dist/web/browser/form-utilities.js.map +1 -1
  50. package/dist/web/browser/geo-location.js +60 -36
  51. package/dist/web/browser/geo-location.js.map +1 -1
  52. package/dist/web/browser/index.js +44 -0
  53. package/dist/web/browser/index.js.map +1 -1
  54. package/dist/web/event-bus.js +65 -0
  55. package/dist/web/event-bus.js.map +1 -0
  56. package/dist/web/index.js +1 -0
  57. package/dist/web/index.js.map +1 -1
  58. package/dist/web/string.js +34 -0
  59. package/dist/web/string.js.map +1 -1
  60. package/package.json +56 -56
  61. package/src/array.ts +0 -0
  62. package/src/async-pool-executor.ts +0 -0
  63. package/src/browser/form-utilities.ts +179 -173
  64. package/src/browser/geo-location.ts +113 -79
  65. package/src/browser/index.ts +78 -4
  66. package/src/browser/native-bridge.ts +116 -116
  67. package/src/cancellable-promise.ts +76 -76
  68. package/src/clean-url-search-params.ts +0 -0
  69. package/src/collections/cache-dictionary.ts +0 -0
  70. package/src/collections/default-map.ts +0 -0
  71. package/src/collections/default-weak-map.ts +0 -0
  72. package/src/collections/index.ts +2 -2
  73. package/src/event-bus.ts +84 -0
  74. package/src/from.ts +0 -0
  75. package/src/index.ts +37 -36
  76. package/src/key-value-pair.ts +0 -0
  77. package/src/lazy.ts +0 -0
  78. package/src/math.ts +0 -0
  79. package/src/order.ts +0 -0
  80. package/src/parse.ts +240 -240
  81. package/src/patch.ts +0 -0
  82. package/src/stopwatch.ts +0 -0
  83. package/src/string.ts +82 -2
  84. package/src/timer.ts +0 -0
  85. package/src/timespan.ts +0 -0
  86. package/src/type-code.ts +15 -15
  87. package/src/type.ts +371 -371
  88. package/src/types.ts +30 -30
  89. package/src/utilities.ts +404 -404
package/src/stopwatch.ts CHANGED
File without changes
package/src/string.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * @param {string} prefix - The prefix to ensure on the string.
7
7
  * @return {string} - The resulting string with the ensured prefix.
8
8
  */
9
- export function ensurePrefix(str: string, prefix: string) {
9
+ export function ensurePrefix(str: string, prefix: string): string {
10
10
  if (!str.startsWith(prefix))
11
11
  return prefix + str
12
12
  return str
@@ -20,7 +20,7 @@ export function ensurePrefix(str: string, prefix: string) {
20
20
  * @param {string} suffix - The suffix to ensure.
21
21
  * @return {string} - The modified string with the suffix added if it was not already present.
22
22
  */
23
- export function ensureSuffix(str: string, suffix: string) {
23
+ export function ensureSuffix(str: string, suffix: string): string {
24
24
  if (!str.endsWith(suffix))
25
25
  return str + suffix
26
26
  return str
@@ -46,4 +46,84 @@ export function format(template: string, ...args: any[]): string {
46
46
  return template.replace(regex, (match, key) => {
47
47
  return typeof args[key] !== 'undefined' ? args[key] : "";
48
48
  });
49
+ }
50
+
51
+ /**
52
+ * Splits a string into its constituent words, regardless of the original case
53
+ * style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,
54
+ * space-separated, etc.).
55
+ *
56
+ * @param {string} str - The string to split into words.
57
+ * @return {string[]} - The list of lowercase words extracted from the input.
58
+ */
59
+ function toWords(str: string): string[] {
60
+ if (!str) return [];
61
+
62
+ return str
63
+ // Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)
64
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
65
+ // Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)
66
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
67
+ // Replace any non-alphanumeric character with a space
68
+ .replace(/[^a-zA-Z0-9]+/g, ' ')
69
+ .trim()
70
+ .toLowerCase()
71
+ .split(/\s+/)
72
+ .filter(Boolean);
73
+ }
74
+
75
+ /**
76
+ * Converts a string to snake_case.
77
+ *
78
+ * @param {string} str - The string to convert.
79
+ * @return {string} - The string converted to snake_case.
80
+ */
81
+ export function toSnakeCase(str: string): string {
82
+ return toWords(str).join('_');
83
+ }
84
+
85
+ /**
86
+ * Converts a string to kebab-case.
87
+ *
88
+ * @param {string} str - The string to convert.
89
+ * @return {string} - The string converted to kebab-case.
90
+ */
91
+ export function toKebabCase(str: string): string {
92
+ return toWords(str).join('-');
93
+ }
94
+
95
+ /**
96
+ * Converts a string to camelCase.
97
+ *
98
+ * @param {string} str - The string to convert.
99
+ * @return {string} - The string converted to camelCase.
100
+ */
101
+ export function toCamelCase(str: string): string {
102
+ const words = toWords(str);
103
+ if (words.length === 0) return '';
104
+ return words
105
+ .map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
106
+ .join('');
107
+ }
108
+
109
+ /**
110
+ * Converts a string to PascalCase.
111
+ *
112
+ * @param {string} str - The string to convert.
113
+ * @return {string} - The string converted to PascalCase.
114
+ */
115
+ export function toPascalCase(str: string): string {
116
+ return toWords(str)
117
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
118
+ .join('');
119
+ }
120
+
121
+ /**
122
+ * Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).
123
+ *
124
+ * @param {string} str - The string to convert.
125
+ * @return {string} - The string converted to CONSTANT_CASE.
126
+ */
127
+ export function toConstantCase(str: string): string {
128
+ return toWords(str).join('_').toUpperCase();
49
129
  }
package/src/timer.ts CHANGED
File without changes
package/src/timespan.ts CHANGED
File without changes
package/src/type-code.ts CHANGED
@@ -1,16 +1,16 @@
1
- enum TypeCode {
2
- String = 'string',
3
- Number = 'number',
4
- Boolean = 'boolean',
5
- Symbol = 'symbol',
6
- BigInt = 'bigint',
7
- Null = 'null',
8
- Undefined = 'undefined',
9
- Object = 'object',
10
- Function = 'function',
11
- Array = 'array',
12
- Unknown = 'unknown',
13
- }
14
-
15
-
1
+ enum TypeCode {
2
+ String = 'string',
3
+ Number = 'number',
4
+ Boolean = 'boolean',
5
+ Symbol = 'symbol',
6
+ BigInt = 'bigint',
7
+ Null = 'null',
8
+ Undefined = 'undefined',
9
+ Object = 'object',
10
+ Function = 'function',
11
+ Array = 'array',
12
+ Unknown = 'unknown',
13
+ }
14
+
15
+
16
16
  export default TypeCode;