@versini/ui-utilities 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/dist/index.d.ts CHANGED
@@ -1,3 +1,43 @@
1
+ /**
2
+ * Converts decimal degrees (DD) to degrees, minutes, and seconds (DMS) format.
3
+ *
4
+ * @param dd - The decimal degrees value to convert.
5
+ * @param lng - If true, treats the value as longitude (E/W); if false, as latitude (N/S).
6
+ * @returns An object containing the direction (dir), degrees (deg), minutes (min), and seconds (sec).
7
+ *
8
+ * @example
9
+ * convertDDToDMS(40.7128, false); // { dir: "N", deg: 40, min: 42, sec: 46.08 }
10
+ * convertDDToDMS(-74.006, true); // { dir: "W", deg: 74, min: 0, sec: 21.6 }
11
+ */
12
+ export declare const convertDDToDMS: (dd: number, lng: boolean) => {
13
+ dir: string;
14
+ deg: number;
15
+ min: number;
16
+ sec: number;
17
+ };
18
+
19
+ /**
20
+ * Converts a latitude value from decimal degrees to a formatted DMS string.
21
+ *
22
+ * @param lat - The latitude in decimal degrees. Optional.
23
+ * @returns A formatted string like "40° 42' 46.08" N" or "N/A" if lat is undefined.
24
+ *
25
+ * @example
26
+ * convertLatitudeToDMS(40.7128); // "40° 42' 46.08" N"
27
+ * convertLatitudeToDMS(-33.8688); // "33° 52' 7.68" S"
28
+ * convertLatitudeToDMS(); // "N/A"
29
+ */
30
+ export declare const convertLatitudeToDMS: (lat?: number) => string;
31
+
32
+ /**
33
+ * Converts camelCase or PascalCase strings into human-readable, title-cased text
34
+ * by inserting spaces before uppercase characters and normalizing whitespace.
35
+ *
36
+ * @param input - The identifier-like string to humanize.
37
+ * @returns A title-cased, space-separated representation of the input.
38
+ */
39
+ export declare const convertStringToHumanReadable: (input: string) => string;
40
+
1
41
  /**
2
42
  * Creates a debounced function that delays invoking the provided function until
3
43
  * after the specified wait time has elapsed since the last time the debounced
@@ -57,4 +97,54 @@ export declare const isProbablyTablet: () => boolean;
57
97
  */
58
98
  export declare const isPWAMode: () => boolean;
59
99
 
100
+ /**
101
+ * A pre-configured Intl.NumberFormat instance for formatting numbers in English
102
+ * locale with no decimal places and no sign display.
103
+ *
104
+ * @example
105
+ * numberFormatter.format(1234567); // Returns "1,234,567"
106
+ * numberFormatter.format(-1234.56); // Returns "1,235"
107
+ * numberFormatter.format(0.789); // Returns "1"
108
+ */
109
+ export declare const numberFormatter: Intl.NumberFormat;
110
+
111
+ /**
112
+ * Encodes a string to Base64, properly handling Unicode characters by first
113
+ * converting to UTF-8 percent-encoding then to raw bytes.
114
+ *
115
+ * @param str - The string to obfuscate.
116
+ * @returns The Base64-encoded string.
117
+ *
118
+ * @example
119
+ * obfuscate("hello"); // Returns "aGVsbG8="
120
+ * obfuscate("héllo"); // Returns "aMOpbGxv" (handles Unicode)
121
+ */
122
+ export declare const obfuscate: (str: string) => string;
123
+
124
+ /**
125
+ * Function that adds an "s" to the end of a word if the count is 0 or greater
126
+ * than 1.
127
+ * @param word - The word to potentially pluralize.
128
+ * @param count - The count to determine if pluralization is needed.
129
+ * @returns The original word if count is 1, otherwise the pluralized word.
130
+ *
131
+ * @example
132
+ * Showing ${pluralize(`${count} chat`, count)} out of ${total}`;
133
+ *
134
+ */
135
+ export declare const pluralize: (word: string, count: number) => string;
136
+
137
+ /**
138
+ * Decodes a Base64-encoded string back to its original form, properly handling
139
+ * Unicode characters by converting from raw bytes to UTF-8 percent-encoding.
140
+ *
141
+ * @param str - The Base64-encoded string to decode.
142
+ * @returns The original decoded string.
143
+ *
144
+ * @example
145
+ * unObfuscate("aGVsbG8="); // Returns "hello"
146
+ * unObfuscate("aMOpbGxv"); // Returns "héllo" (handles Unicode)
147
+ */
148
+ export declare const unObfuscate: (str: string) => string;
149
+
60
150
  export { }
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- @versini/ui-utilities v1.1.0
2
+ @versini/ui-utilities v1.3.0
3
3
  © 2025 gizmette.com
4
4
  */
5
5
  try {
6
6
  if (!window.__VERSINI_UI_UTILITIES__) {
7
7
  window.__VERSINI_UI_UTILITIES__ = {
8
- version: "1.1.0",
9
- buildTime: "12/19/2025 03:10 PM EST",
8
+ version: "1.3.0",
9
+ buildTime: "12/19/2025 08:08 PM EST",
10
10
  homepage: "https://www.npmjs.com/package/@versini/ui-utilities",
11
11
  license: "MIT",
12
12
  };
@@ -92,6 +92,121 @@ try {
92
92
  *
93
93
  */ /* c8 ignore start */ const isPWAMode = ()=>{
94
94
  return window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === true;
95
- }; /* c8 ignore stop */
95
+ };
96
+ /* c8 ignore stop */ /**
97
+ * Function that adds an "s" to the end of a word if the count is 0 or greater
98
+ * than 1.
99
+ * @param word - The word to potentially pluralize.
100
+ * @param count - The count to determine if pluralization is needed.
101
+ * @returns The original word if count is 1, otherwise the pluralized word.
102
+ *
103
+ * @example
104
+ * Showing ${pluralize(`${count} chat`, count)} out of ${total}`;
105
+ *
106
+ */ const pluralize = (word, count)=>{
107
+ return count === 1 ? word : `${word}s`;
108
+ };
109
+ /**
110
+ * A pre-configured Intl.NumberFormat instance for formatting numbers in English
111
+ * locale with no decimal places and no sign display.
112
+ *
113
+ * @example
114
+ * numberFormatter.format(1234567); // Returns "1,234,567"
115
+ * numberFormatter.format(-1234.56); // Returns "1,235"
116
+ * numberFormatter.format(0.789); // Returns "1"
117
+ */ const numberFormatter = new Intl.NumberFormat("en", {
118
+ signDisplay: "never",
119
+ maximumFractionDigits: 0
120
+ });
121
+ /**
122
+ * Encodes a string to Base64, properly handling Unicode characters by first
123
+ * converting to UTF-8 percent-encoding then to raw bytes.
124
+ *
125
+ * @param str - The string to obfuscate.
126
+ * @returns The Base64-encoded string.
127
+ *
128
+ * @example
129
+ * obfuscate("hello"); // Returns "aGVsbG8="
130
+ * obfuscate("héllo"); // Returns "aMOpbGxv" (handles Unicode)
131
+ */ const obfuscate = (str)=>{
132
+ /**
133
+ * First we use encodeURIComponent to get percent-encoded. UTF-8, then we
134
+ * convert the percent encodings into raw bytes which can be fed into btoa.
135
+ */ return window.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes(_match, p1) {
136
+ return String.fromCharCode(Number(`0x${p1}`));
137
+ }));
138
+ };
139
+ /**
140
+ * Decodes a Base64-encoded string back to its original form, properly handling
141
+ * Unicode characters by converting from raw bytes to UTF-8 percent-encoding.
142
+ *
143
+ * @param str - The Base64-encoded string to decode.
144
+ * @returns The original decoded string.
145
+ *
146
+ * @example
147
+ * unObfuscate("aGVsbG8="); // Returns "hello"
148
+ * unObfuscate("aMOpbGxv"); // Returns "héllo" (handles Unicode)
149
+ */ const unObfuscate = (str)=>{
150
+ /**
151
+ * Going backwards: from bytestream, to percent-encoding, to original string.
152
+ */ return decodeURIComponent(window.atob(str).split("").map(function(c) {
153
+ return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;
154
+ }).join(""));
155
+ };
156
+ /**
157
+ * Converts decimal degrees (DD) to degrees, minutes, and seconds (DMS) format.
158
+ *
159
+ * @param dd - The decimal degrees value to convert.
160
+ * @param lng - If true, treats the value as longitude (E/W); if false, as latitude (N/S).
161
+ * @returns An object containing the direction (dir), degrees (deg), minutes (min), and seconds (sec).
162
+ *
163
+ * @example
164
+ * convertDDToDMS(40.7128, false); // { dir: "N", deg: 40, min: 42, sec: 46.08 }
165
+ * convertDDToDMS(-74.006, true); // { dir: "W", deg: 74, min: 0, sec: 21.6 }
166
+ */ const convertDDToDMS = (dd, lng)=>{
167
+ const dir = dd < 0 ? lng ? "W" : "S" : lng ? "E" : "N";
168
+ const deg = 0 | Math.abs(dd);
169
+ const min = 0 | Math.abs(dd) * 60 % 60;
170
+ const sec = (0 | Math.abs(dd) * 60 % 1 * 6000) / 100;
171
+ return {
172
+ dir,
173
+ deg,
174
+ min,
175
+ sec
176
+ };
177
+ };
178
+ /**
179
+ * Converts a latitude value from decimal degrees to a formatted DMS string.
180
+ *
181
+ * @param lat - The latitude in decimal degrees. Optional.
182
+ * @returns A formatted string like "40° 42' 46.08" N" or "N/A" if lat is undefined.
183
+ *
184
+ * @example
185
+ * convertLatitudeToDMS(40.7128); // "40° 42' 46.08" N"
186
+ * convertLatitudeToDMS(-33.8688); // "33° 52' 7.68" S"
187
+ * convertLatitudeToDMS(); // "N/A"
188
+ */ const convertLatitudeToDMS = (lat)=>{
189
+ if (!lat && lat !== 0) {
190
+ return "N/A";
191
+ }
192
+ const latitude = convertDDToDMS(lat, false);
193
+ return `${latitude.deg}° ${latitude.min}' ${latitude.sec}" ${latitude.dir}`;
194
+ };
195
+ /**
196
+ * Converts camelCase or PascalCase strings into human-readable, title-cased text
197
+ * by inserting spaces before uppercase characters and normalizing whitespace.
198
+ *
199
+ * @param input - The identifier-like string to humanize.
200
+ * @returns A title-cased, space-separated representation of the input.
201
+ */ const convertStringToHumanReadable = (input)=>{
202
+ if (!input) {
203
+ return "";
204
+ }
205
+ const normalized = input.replace(/([A-Z])/g, " $1").replace(/\s+/g, " ").trim();
206
+ if (!normalized) {
207
+ return "";
208
+ }
209
+ return normalized.charAt(0).toUpperCase() + normalized.slice(1);
210
+ };
96
211
 
97
- export { debounce, isPWAMode, isProbablyMobile, isProbablyTablet, isProbablyiPad, isProbablyiPhone };
212
+ export { convertDDToDMS, convertLatitudeToDMS, convertStringToHumanReadable, debounce, isPWAMode, isProbablyMobile, isProbablyTablet, isProbablyiPad, isProbablyiPhone, numberFormatter, obfuscate, pluralize, unObfuscate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-utilities",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -39,5 +39,5 @@
39
39
  "sideEffects": [
40
40
  "**/*.css"
41
41
  ],
42
- "gitHead": "8c05a346766c79bba8ecbeb68c7adbb1e8c5e50c"
42
+ "gitHead": "3cd6b66a229c88f97e68f9de9cea8d4fabbb55ae"
43
43
  }