@tim-code/my-util 0.8.0 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-code/my-util",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "author": "Tim Sprowl",
package/src/array.js CHANGED
@@ -194,6 +194,12 @@ function naturalCompare(a, b) {
194
194
  b = b.slice(1, b.length)
195
195
  return b.localeCompare(a, undefined, { numeric: true })
196
196
  }
197
+ if (a[0] === "+" && !Number.isNaN(Number(a))) {
198
+ a = a.slice(1, a.length)
199
+ }
200
+ if (b[0] === "+" && !Number.isNaN(Number(b))) {
201
+ b = b.slice(1, b.length)
202
+ }
197
203
  return a.localeCompare(b, undefined, { numeric: true })
198
204
  }
199
205
 
package/src/array.test.js CHANGED
@@ -542,6 +542,18 @@ describe("naturalAsc", () => {
542
542
  arr.sort(naturalAsc())
543
543
  expect(arr).toEqual(["-10", "-2", "-1"])
544
544
  })
545
+
546
+ it("can sort negative to positive", () => {
547
+ const arr = ["-2", "+5", "0"]
548
+ arr.sort(naturalAsc())
549
+ expect(arr).toEqual(["-2", "0", "+5"])
550
+ })
551
+
552
+ it("handles leading plus signs on numeric-like strings", () => {
553
+ const arr = ["a", "+10", "+2", "+1"]
554
+ arr.sort(naturalAsc())
555
+ expect(arr).toEqual(["+1", "+2", "+10", "a"])
556
+ })
545
557
  })
546
558
 
547
559
  describe("naturalDesc", () => {
@@ -586,6 +598,18 @@ describe("naturalDesc", () => {
586
598
  arr.sort(naturalDesc())
587
599
  expect(arr).toEqual(["-1", "-2", "-10"])
588
600
  })
601
+
602
+ it("can sort positive to negative", () => {
603
+ const arr = ["+5", "-2", "0"]
604
+ arr.sort(naturalDesc())
605
+ expect(arr).toEqual(["+5", "0", "-2"])
606
+ })
607
+
608
+ it("handles leading plus signs on numeric-like strings (descending)", () => {
609
+ const arr = ["+1", "+2", "+10", "a"]
610
+ arr.sort(naturalDesc())
611
+ expect(arr).toEqual(["a", "+10", "+2", "+1"])
612
+ })
589
613
  })
590
614
 
591
615
  describe("multilevel", () => {
package/src/time.js CHANGED
@@ -1,9 +1,5 @@
1
1
  import { mod } from "./math.js"
2
2
 
3
- // `floorMinute` at first glance seems ugly and something like `floor: "minute"` seems better.
4
- // However, practically and realistically, it doesn't seem like we need other values for floor besides "second" and "minute".
5
- // So, then it seems more problematic to rely on an exact string to be passed... probably would need to throw on some other value.
6
- // We don't really ever want to disable flooring because we want timestamp, date, and time returned to represent the same thing.
7
3
  /**
8
4
  * Gets various ways of representing the current time in EDT. Floors to nearest second by default.
9
5
  * @param {Object} $1
@@ -91,7 +87,7 @@ export function getDayIndexInWeek(string = today()) {
91
87
 
92
88
  /**
93
89
  * Get the minute from a time string.
94
- * @param {string} time HH:mm or HH:mm::ss
90
+ * @param {string} time HH:mm or HH:mm:ss
95
91
  * @returns {number} Between 0 and 59 inclusive
96
92
  */
97
93
  export function getMinute(time) {