swcombine.js 0.0.9 → 0.0.11
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.cjs.js +73 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.esm.js +73 -5
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -254,18 +254,29 @@ const _SwcTimestamp = class _SwcTimestamp {
|
|
|
254
254
|
return secondsToDuration(endTime - startTime);
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
|
-
* Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21)
|
|
258
|
-
*
|
|
257
|
+
* Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21).
|
|
258
|
+
* You can either pass in a preset name, or a custom format string.
|
|
259
|
+
* The following preset formats are available:
|
|
259
260
|
*
|
|
260
261
|
* 'full': Year 25 Day 60, 6:03:12<br>
|
|
261
262
|
* 'minute': Year 25 Day 60, 6:03<br>
|
|
262
263
|
* 'day': Year 25 Day 60<br>
|
|
263
264
|
* 'shortFull': Y25 D60, 6:03:12<br>
|
|
264
265
|
* 'shortMinute': Y25 D60, 6:03<br>
|
|
265
|
-
* 'shortDay': Y26 D60
|
|
266
|
-
*
|
|
266
|
+
* 'shortDay': Y26 D60<br>
|
|
267
|
+
* <br>
|
|
268
|
+
* If passing in a custom formatting string, you can use substitution tags to fill in variables. These tags are wrapped in {} and are case-insensitive. The following substitution tags are available:<br>
|
|
269
|
+
* {y}: year<br>
|
|
270
|
+
* {d}: day<br>
|
|
271
|
+
* {h}: hour<br>
|
|
272
|
+
* {m}: minute<br>
|
|
273
|
+
* {s}: second<br>
|
|
274
|
+
* double the tag to get leading zeroes. i.e. {h} = 8, {hh} = 08.<br>
|
|
275
|
+
* {hms} is a shorthand for {hh}:{mm}:{ss}.<br>
|
|
276
|
+
* Example: '{hms} on Day {d} of Year {y}' becomes '08:12:14 on Day 6 of Year 25'.
|
|
277
|
+
* @param format format to use, or custom formatting string.
|
|
267
278
|
*/
|
|
268
|
-
toString(format) {
|
|
279
|
+
toString(format = "full") {
|
|
269
280
|
switch (format) {
|
|
270
281
|
case "full":
|
|
271
282
|
return `Year ${this.year} Day ${this.day}, ${this.hour}:${this.minute.toString().padStart(2, "0")}:${this.second.toString().padStart(2, "0")}`;
|
|
@@ -280,6 +291,63 @@ const _SwcTimestamp = class _SwcTimestamp {
|
|
|
280
291
|
case "shortDay":
|
|
281
292
|
return `Y${this.year} D${this.day}`;
|
|
282
293
|
}
|
|
294
|
+
let formattedString = "";
|
|
295
|
+
let currentTag = "";
|
|
296
|
+
let isInTag = false;
|
|
297
|
+
format.split("").forEach((char) => {
|
|
298
|
+
if (char === "{" && !isInTag) {
|
|
299
|
+
isInTag = true;
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (char === "}" && isInTag) {
|
|
303
|
+
formattedString += this.substituteTag(currentTag);
|
|
304
|
+
isInTag = false;
|
|
305
|
+
currentTag = "";
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (isInTag) {
|
|
309
|
+
currentTag += char;
|
|
310
|
+
} else {
|
|
311
|
+
formattedString += char;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return formattedString;
|
|
315
|
+
}
|
|
316
|
+
substituteTag(tag) {
|
|
317
|
+
if (tag.localeCompare("y", "en", { sensitivity: "accent" }) === 0) {
|
|
318
|
+
return this.year.toString();
|
|
319
|
+
}
|
|
320
|
+
if (tag.localeCompare("yy", "en", { sensitivity: "accent" }) === 0) {
|
|
321
|
+
return this.year.toString().padStart(2, "0");
|
|
322
|
+
}
|
|
323
|
+
if (tag.localeCompare("d", "en", { sensitivity: "accent" }) === 0) {
|
|
324
|
+
return this.day.toString();
|
|
325
|
+
}
|
|
326
|
+
if (tag.localeCompare("dd", "en", { sensitivity: "accent" }) === 0) {
|
|
327
|
+
return this.day.toString().padStart(2, "0");
|
|
328
|
+
}
|
|
329
|
+
if (tag.localeCompare("h", "en", { sensitivity: "accent" }) === 0) {
|
|
330
|
+
return this.hour.toString();
|
|
331
|
+
}
|
|
332
|
+
if (tag.localeCompare("hh", "en", { sensitivity: "accent" }) === 0) {
|
|
333
|
+
return this.hour.toString().padStart(2, "0");
|
|
334
|
+
}
|
|
335
|
+
if (tag.localeCompare("m", "en", { sensitivity: "accent" }) === 0) {
|
|
336
|
+
return this.minute.toString();
|
|
337
|
+
}
|
|
338
|
+
if (tag.localeCompare("mm", "en", { sensitivity: "accent" }) === 0) {
|
|
339
|
+
return this.minute.toString().padStart(2, "0");
|
|
340
|
+
}
|
|
341
|
+
if (tag.localeCompare("s", "en", { sensitivity: "accent" }) === 0) {
|
|
342
|
+
return this.second.toString();
|
|
343
|
+
}
|
|
344
|
+
if (tag.localeCompare("ss", "en", { sensitivity: "accent" }) === 0) {
|
|
345
|
+
return this.second.toString().padStart(2, "0");
|
|
346
|
+
}
|
|
347
|
+
if (tag.localeCompare("hms", "en", { sensitivity: "accent" }) === 0) {
|
|
348
|
+
return `${this.hour.toString().padStart(2, "0")}:${this.minute.toString().padStart(2, "0")}:${this.second.toString().padStart(2, "0")}`;
|
|
349
|
+
}
|
|
350
|
+
return "";
|
|
283
351
|
}
|
|
284
352
|
/**
|
|
285
353
|
* @returns {number}
|
package/dist/index.d.ts
CHANGED
|
@@ -441,18 +441,30 @@ export declare class SwcTimestamp {
|
|
|
441
441
|
subtract(duration: Partial<Duration>): SwcTimestamp;
|
|
442
442
|
getDurationTo(otherTimestamp: SwcTimestamp): Duration;
|
|
443
443
|
/**
|
|
444
|
-
* Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21)
|
|
445
|
-
*
|
|
444
|
+
* Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21).
|
|
445
|
+
* You can either pass in a preset name, or a custom format string.
|
|
446
|
+
* The following preset formats are available:
|
|
446
447
|
*
|
|
447
448
|
* 'full': Year 25 Day 60, 6:03:12<br>
|
|
448
449
|
* 'minute': Year 25 Day 60, 6:03<br>
|
|
449
450
|
* 'day': Year 25 Day 60<br>
|
|
450
451
|
* 'shortFull': Y25 D60, 6:03:12<br>
|
|
451
452
|
* 'shortMinute': Y25 D60, 6:03<br>
|
|
452
|
-
* 'shortDay': Y26 D60
|
|
453
|
-
*
|
|
453
|
+
* 'shortDay': Y26 D60<br>
|
|
454
|
+
* <br>
|
|
455
|
+
* If passing in a custom formatting string, you can use substitution tags to fill in variables. These tags are wrapped in {} and are case-insensitive. The following substitution tags are available:<br>
|
|
456
|
+
* {y}: year<br>
|
|
457
|
+
* {d}: day<br>
|
|
458
|
+
* {h}: hour<br>
|
|
459
|
+
* {m}: minute<br>
|
|
460
|
+
* {s}: second<br>
|
|
461
|
+
* double the tag to get leading zeroes. i.e. {h} = 8, {hh} = 08.<br>
|
|
462
|
+
* {hms} is a shorthand for {hh}:{mm}:{ss}.<br>
|
|
463
|
+
* Example: '{hms} on Day {d} of Year {y}' becomes '08:12:14 on Day 6 of Year 25'.
|
|
464
|
+
* @param format format to use, or custom formatting string.
|
|
454
465
|
*/
|
|
455
|
-
toString(format
|
|
466
|
+
toString(format?: 'full' | 'minute' | 'day' | 'shortFull' | 'shortMinute' | 'shortDay' | string): string;
|
|
467
|
+
private substituteTag;
|
|
456
468
|
/**
|
|
457
469
|
* @returns {number}
|
|
458
470
|
* @private
|
package/dist/index.esm.js
CHANGED
|
@@ -252,18 +252,29 @@ const _SwcTimestamp = class _SwcTimestamp {
|
|
|
252
252
|
return secondsToDuration(endTime - startTime);
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
|
-
* Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21)
|
|
256
|
-
*
|
|
255
|
+
* Convert the SWC timestamp to a string (i.e. Year 25 Day 60, 12:45:21).
|
|
256
|
+
* You can either pass in a preset name, or a custom format string.
|
|
257
|
+
* The following preset formats are available:
|
|
257
258
|
*
|
|
258
259
|
* 'full': Year 25 Day 60, 6:03:12<br>
|
|
259
260
|
* 'minute': Year 25 Day 60, 6:03<br>
|
|
260
261
|
* 'day': Year 25 Day 60<br>
|
|
261
262
|
* 'shortFull': Y25 D60, 6:03:12<br>
|
|
262
263
|
* 'shortMinute': Y25 D60, 6:03<br>
|
|
263
|
-
* 'shortDay': Y26 D60
|
|
264
|
-
*
|
|
264
|
+
* 'shortDay': Y26 D60<br>
|
|
265
|
+
* <br>
|
|
266
|
+
* If passing in a custom formatting string, you can use substitution tags to fill in variables. These tags are wrapped in {} and are case-insensitive. The following substitution tags are available:<br>
|
|
267
|
+
* {y}: year<br>
|
|
268
|
+
* {d}: day<br>
|
|
269
|
+
* {h}: hour<br>
|
|
270
|
+
* {m}: minute<br>
|
|
271
|
+
* {s}: second<br>
|
|
272
|
+
* double the tag to get leading zeroes. i.e. {h} = 8, {hh} = 08.<br>
|
|
273
|
+
* {hms} is a shorthand for {hh}:{mm}:{ss}.<br>
|
|
274
|
+
* Example: '{hms} on Day {d} of Year {y}' becomes '08:12:14 on Day 6 of Year 25'.
|
|
275
|
+
* @param format format to use, or custom formatting string.
|
|
265
276
|
*/
|
|
266
|
-
toString(format) {
|
|
277
|
+
toString(format = "full") {
|
|
267
278
|
switch (format) {
|
|
268
279
|
case "full":
|
|
269
280
|
return `Year ${this.year} Day ${this.day}, ${this.hour}:${this.minute.toString().padStart(2, "0")}:${this.second.toString().padStart(2, "0")}`;
|
|
@@ -278,6 +289,63 @@ const _SwcTimestamp = class _SwcTimestamp {
|
|
|
278
289
|
case "shortDay":
|
|
279
290
|
return `Y${this.year} D${this.day}`;
|
|
280
291
|
}
|
|
292
|
+
let formattedString = "";
|
|
293
|
+
let currentTag = "";
|
|
294
|
+
let isInTag = false;
|
|
295
|
+
format.split("").forEach((char) => {
|
|
296
|
+
if (char === "{" && !isInTag) {
|
|
297
|
+
isInTag = true;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (char === "}" && isInTag) {
|
|
301
|
+
formattedString += this.substituteTag(currentTag);
|
|
302
|
+
isInTag = false;
|
|
303
|
+
currentTag = "";
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (isInTag) {
|
|
307
|
+
currentTag += char;
|
|
308
|
+
} else {
|
|
309
|
+
formattedString += char;
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
return formattedString;
|
|
313
|
+
}
|
|
314
|
+
substituteTag(tag) {
|
|
315
|
+
if (tag.localeCompare("y", "en", { sensitivity: "accent" }) === 0) {
|
|
316
|
+
return this.year.toString();
|
|
317
|
+
}
|
|
318
|
+
if (tag.localeCompare("yy", "en", { sensitivity: "accent" }) === 0) {
|
|
319
|
+
return this.year.toString().padStart(2, "0");
|
|
320
|
+
}
|
|
321
|
+
if (tag.localeCompare("d", "en", { sensitivity: "accent" }) === 0) {
|
|
322
|
+
return this.day.toString();
|
|
323
|
+
}
|
|
324
|
+
if (tag.localeCompare("dd", "en", { sensitivity: "accent" }) === 0) {
|
|
325
|
+
return this.day.toString().padStart(2, "0");
|
|
326
|
+
}
|
|
327
|
+
if (tag.localeCompare("h", "en", { sensitivity: "accent" }) === 0) {
|
|
328
|
+
return this.hour.toString();
|
|
329
|
+
}
|
|
330
|
+
if (tag.localeCompare("hh", "en", { sensitivity: "accent" }) === 0) {
|
|
331
|
+
return this.hour.toString().padStart(2, "0");
|
|
332
|
+
}
|
|
333
|
+
if (tag.localeCompare("m", "en", { sensitivity: "accent" }) === 0) {
|
|
334
|
+
return this.minute.toString();
|
|
335
|
+
}
|
|
336
|
+
if (tag.localeCompare("mm", "en", { sensitivity: "accent" }) === 0) {
|
|
337
|
+
return this.minute.toString().padStart(2, "0");
|
|
338
|
+
}
|
|
339
|
+
if (tag.localeCompare("s", "en", { sensitivity: "accent" }) === 0) {
|
|
340
|
+
return this.second.toString();
|
|
341
|
+
}
|
|
342
|
+
if (tag.localeCompare("ss", "en", { sensitivity: "accent" }) === 0) {
|
|
343
|
+
return this.second.toString().padStart(2, "0");
|
|
344
|
+
}
|
|
345
|
+
if (tag.localeCompare("hms", "en", { sensitivity: "accent" }) === 0) {
|
|
346
|
+
return `${this.hour.toString().padStart(2, "0")}:${this.minute.toString().padStart(2, "0")}:${this.second.toString().padStart(2, "0")}`;
|
|
347
|
+
}
|
|
348
|
+
return "";
|
|
281
349
|
}
|
|
282
350
|
/**
|
|
283
351
|
* @returns {number}
|