@naturalcycles/js-lib 15.106.1 → 15.107.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.
@@ -309,13 +309,7 @@ export class LocalDate {
309
309
  }
310
310
  else {
311
311
  let monLen = localDate.getMonthLength(year, month);
312
- if (unit !== 'day') {
313
- if (day > monLen) {
314
- // Case of 2022-05-31 plus 1 month should be 2022-06-30, not 31
315
- day = monLen;
316
- }
317
- }
318
- else {
312
+ if (unit === 'day') {
319
313
  while (day > monLen) {
320
314
  day -= monLen;
321
315
  month += 1;
@@ -326,6 +320,12 @@ export class LocalDate {
326
320
  monLen = localDate.getMonthLength(year, month);
327
321
  }
328
322
  }
323
+ else {
324
+ if (day > monLen) {
325
+ // Case of 2022-05-31 plus 1 month should be 2022-06-30, not 31
326
+ day = monLen;
327
+ }
328
+ }
329
329
  }
330
330
  if (opt.mutate) {
331
331
  this.year = year;
@@ -24,14 +24,14 @@ function serializer(replacer, cycleReplacer) {
24
24
  return function (key, value) {
25
25
  if (stack.length > 0) {
26
26
  const thisPos = stack.indexOf(this);
27
- if (thisPos !== -1) {
28
- stack.splice(thisPos + 1);
29
- keys.splice(thisPos, Infinity, key);
30
- }
31
- else {
27
+ if (thisPos === -1) {
32
28
  stack.push(this);
33
29
  keys.push(key);
34
30
  }
31
+ else {
32
+ stack.splice(thisPos + 1);
33
+ keys.splice(thisPos, Infinity, key);
34
+ }
35
35
  if (stack.includes(value)) {
36
36
  value = cycleReplacer.call(this, key, value);
37
37
  }
@@ -64,19 +64,19 @@ export function _truncateMiddle(s, maxLen, omission = '...') {
64
64
  // These functions are modeled after Kotlin's String API
65
65
  export function _substringBefore(s, delimiter) {
66
66
  const pos = s.indexOf(delimiter);
67
- return s.slice(0, pos !== -1 ? pos : undefined);
67
+ return s.slice(0, pos === -1 ? undefined : pos);
68
68
  }
69
69
  export function _substringBeforeLast(s, delimiter) {
70
70
  const pos = s.lastIndexOf(delimiter);
71
- return s.slice(0, pos !== -1 ? pos : undefined);
71
+ return s.slice(0, pos === -1 ? undefined : pos);
72
72
  }
73
73
  export function _substringAfter(s, delimiter) {
74
74
  const pos = s.indexOf(delimiter);
75
- return pos !== -1 ? s.slice(pos + delimiter.length) : s;
75
+ return pos === -1 ? s : s.slice(pos + delimiter.length);
76
76
  }
77
77
  export function _substringAfterLast(s, delimiter) {
78
78
  const pos = s.lastIndexOf(delimiter);
79
- return pos !== -1 ? s.slice(pos + delimiter.length) : s;
79
+ return pos === -1 ? s : s.slice(pos + delimiter.length);
80
80
  }
81
81
  /**
82
82
  * Returns the substring between LAST `leftDelimiter` and then FIRST `rightDelimiter`.
package/dist/ua/ua.js CHANGED
@@ -71,7 +71,7 @@ export function uaParser(userAgent, extensions) {
71
71
  */
72
72
  export class UAParser {
73
73
  constructor(ua, extensions) {
74
- this.nav = typeof globalThis.window !== 'undefined' ? globalThis.navigator : undefined;
74
+ this.nav = typeof globalThis.window === 'undefined' ? undefined : globalThis.navigator;
75
75
  this.rgxMap = extensions ? extend(regexes, extensions) : regexes;
76
76
  const initialUa = ua || this.nav?.userAgent || '';
77
77
  // Whether we're parsing the environment's own UA - only then the
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.106.1",
4
+ "version": "15.107.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2"
7
7
  },
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "devDependencies": {
17
- "@naturalcycles/dev-lib": "0.0.0",
17
+ "@naturalcycles/dev-lib": "20.79.0",
18
18
  "@types/node": "^26",
19
19
  "@types/semver": "^7",
20
20
  "rolldown": "^1",
@@ -373,12 +373,7 @@ export class LocalDate {
373
373
  } else {
374
374
  let monLen = localDate.getMonthLength(year, month)
375
375
 
376
- if (unit !== 'day') {
377
- if (day > monLen) {
378
- // Case of 2022-05-31 plus 1 month should be 2022-06-30, not 31
379
- day = monLen
380
- }
381
- } else {
376
+ if (unit === 'day') {
382
377
  while (day > monLen) {
383
378
  day -= monLen
384
379
  month += 1
@@ -389,6 +384,11 @@ export class LocalDate {
389
384
 
390
385
  monLen = localDate.getMonthLength(year, month)
391
386
  }
387
+ } else {
388
+ if (day > monLen) {
389
+ // Case of 2022-05-31 plus 1 month should be 2022-06-30, not 31
390
+ day = monLen
391
+ }
392
392
  }
393
393
  }
394
394
 
@@ -32,12 +32,12 @@ function serializer(replacer?: Reviver, cycleReplacer?: Reviver): Reviver {
32
32
  return function (key, value) {
33
33
  if (stack.length > 0) {
34
34
  const thisPos = stack.indexOf(this)
35
- if (thisPos !== -1) {
36
- stack.splice(thisPos + 1)
37
- keys.splice(thisPos, Infinity, key)
38
- } else {
35
+ if (thisPos === -1) {
39
36
  stack.push(this)
40
37
  keys.push(key)
38
+ } else {
39
+ stack.splice(thisPos + 1)
40
+ keys.splice(thisPos, Infinity, key)
41
41
  }
42
42
 
43
43
  if (stack.includes(value)) {
@@ -70,22 +70,22 @@ export function _truncateMiddle(s: string, maxLen: number, omission = '...'): st
70
70
 
71
71
  export function _substringBefore(s: string, delimiter: string): string {
72
72
  const pos = s.indexOf(delimiter)
73
- return s.slice(0, pos !== -1 ? pos : undefined)
73
+ return s.slice(0, pos === -1 ? undefined : pos)
74
74
  }
75
75
 
76
76
  export function _substringBeforeLast(s: string, delimiter: string): string {
77
77
  const pos = s.lastIndexOf(delimiter)
78
- return s.slice(0, pos !== -1 ? pos : undefined)
78
+ return s.slice(0, pos === -1 ? undefined : pos)
79
79
  }
80
80
 
81
81
  export function _substringAfter(s: string, delimiter: string): string {
82
82
  const pos = s.indexOf(delimiter)
83
- return pos !== -1 ? s.slice(pos + delimiter.length) : s
83
+ return pos === -1 ? s : s.slice(pos + delimiter.length)
84
84
  }
85
85
 
86
86
  export function _substringAfterLast(s: string, delimiter: string): string {
87
87
  const pos = s.lastIndexOf(delimiter)
88
- return pos !== -1 ? s.slice(pos + delimiter.length) : s
88
+ return pos === -1 ? s : s.slice(pos + delimiter.length)
89
89
  }
90
90
 
91
91
  /**
package/src/ua/ua.ts CHANGED
@@ -180,7 +180,7 @@ export function uaParser(userAgent?: string, extensions?: UAParserExtensions): U
180
180
  */
181
181
  export class UAParser {
182
182
  constructor(ua?: string, extensions?: UAParserExtensions) {
183
- this.nav = typeof globalThis.window !== 'undefined' ? globalThis.navigator : undefined
183
+ this.nav = typeof globalThis.window === 'undefined' ? undefined : globalThis.navigator
184
184
  this.rgxMap = extensions ? extend(regexes, extensions) : regexes
185
185
  const initialUa = ua || this.nav?.userAgent || ''
186
186
  // Whether we're parsing the environment's own UA - only then the