@versini/ui-utilities 1.1.0 → 1.2.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,34 @@
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
+
1
32
  /**
2
33
  * Creates a debounced function that delays invoking the provided function until
3
34
  * after the specified wait time has elapsed since the last time the debounced
@@ -57,4 +88,54 @@ export declare const isProbablyTablet: () => boolean;
57
88
  */
58
89
  export declare const isPWAMode: () => boolean;
59
90
 
91
+ /**
92
+ * A pre-configured Intl.NumberFormat instance for formatting numbers in English
93
+ * locale with no decimal places and no sign display.
94
+ *
95
+ * @example
96
+ * numberFormatter.format(1234567); // Returns "1,234,567"
97
+ * numberFormatter.format(-1234.56); // Returns "1,235"
98
+ * numberFormatter.format(0.789); // Returns "1"
99
+ */
100
+ export declare const numberFormatter: Intl.NumberFormat;
101
+
102
+ /**
103
+ * Encodes a string to Base64, properly handling Unicode characters by first
104
+ * converting to UTF-8 percent-encoding then to raw bytes.
105
+ *
106
+ * @param str - The string to obfuscate.
107
+ * @returns The Base64-encoded string.
108
+ *
109
+ * @example
110
+ * obfuscate("hello"); // Returns "aGVsbG8="
111
+ * obfuscate("héllo"); // Returns "aMOpbGxv" (handles Unicode)
112
+ */
113
+ export declare const obfuscate: (str: string) => string;
114
+
115
+ /**
116
+ * Function that adds an "s" to the end of a word if the count is 0 or greater
117
+ * than 1.
118
+ * @param word - The word to potentially pluralize.
119
+ * @param count - The count to determine if pluralization is needed.
120
+ * @returns The original word if count is 1, otherwise the pluralized word.
121
+ *
122
+ * @example
123
+ * Showing ${pluralize(`${count} chat`, count)} out of ${total}`;
124
+ *
125
+ */
126
+ export declare const pluralize: (word: string, count: number) => string;
127
+
128
+ /**
129
+ * Decodes a Base64-encoded string back to its original form, properly handling
130
+ * Unicode characters by converting from raw bytes to UTF-8 percent-encoding.
131
+ *
132
+ * @param str - The Base64-encoded string to decode.
133
+ * @returns The original decoded string.
134
+ *
135
+ * @example
136
+ * unObfuscate("aGVsbG8="); // Returns "hello"
137
+ * unObfuscate("aMOpbGxv"); // Returns "héllo" (handles Unicode)
138
+ */
139
+ export declare const unObfuscate: (str: string) => string;
140
+
60
141
  export { }
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- @versini/ui-utilities v1.1.0
2
+ @versini/ui-utilities v1.2.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.2.0",
9
+ buildTime: "12/19/2025 07:11 PM EST",
10
10
  homepage: "https://www.npmjs.com/package/@versini/ui-utilities",
11
11
  license: "MIT",
12
12
  };
@@ -92,6 +92,105 @@ 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
+ };
96
195
 
97
- export { debounce, isPWAMode, isProbablyMobile, isProbablyTablet, isProbablyiPad, isProbablyiPhone };
196
+ export { convertDDToDMS, convertLatitudeToDMS, 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.2.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": "e2ff3943a0cbf0481490bd3c8d6fc4b3f1d93b2f"
43
43
  }