@naturalcycles/js-lib 14.115.1 → 14.115.2

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.
@@ -40,7 +40,9 @@ exports._removeWhitespace = _removeWhitespace;
40
40
  function _truncate(s, maxLen, omission = '...') {
41
41
  if (!s || s.length <= maxLen)
42
42
  return s;
43
- return s.substr(0, maxLen - omission.length) + omission;
43
+ if (maxLen <= omission.length)
44
+ return omission;
45
+ return s.slice(0, maxLen - omission.length) + omission;
44
46
  }
45
47
  exports._truncate = _truncate;
46
48
  /**
@@ -50,30 +52,32 @@ exports._truncate = _truncate;
50
52
  function _truncateMiddle(s, maxLen, omission = '...') {
51
53
  if (!s || s.length <= maxLen)
52
54
  return s;
55
+ if (maxLen <= omission.length)
56
+ return omission;
53
57
  const mark1 = Math.round((maxLen - omission.length) / 2);
54
58
  const mark2 = s.length - Math.floor((maxLen - omission.length) / 2);
55
- return s.substr(0, mark1) + omission + s.substr(mark2);
59
+ return s.slice(0, mark1) + omission + s.slice(mark2);
56
60
  }
57
61
  exports._truncateMiddle = _truncateMiddle;
58
62
  // These functions are modeled after Kotlin's String API
59
63
  function _substringBefore(s, delimiter) {
60
64
  const pos = s.indexOf(delimiter);
61
- return s.substr(0, pos !== -1 ? pos : undefined);
65
+ return s.slice(0, pos !== -1 ? pos : undefined);
62
66
  }
63
67
  exports._substringBefore = _substringBefore;
64
68
  function _substringBeforeLast(s, delimiter) {
65
69
  const pos = s.lastIndexOf(delimiter);
66
- return s.substr(0, pos !== -1 ? pos : undefined);
70
+ return s.slice(0, pos !== -1 ? pos : undefined);
67
71
  }
68
72
  exports._substringBeforeLast = _substringBeforeLast;
69
73
  function _substringAfter(s, delimiter) {
70
74
  const pos = s.indexOf(delimiter);
71
- return pos !== -1 ? s.substr(pos + 1) : s;
75
+ return pos !== -1 ? s.slice(pos + 1) : s;
72
76
  }
73
77
  exports._substringAfter = _substringAfter;
74
78
  function _substringAfterLast(s, delimiter) {
75
79
  const pos = s.lastIndexOf(delimiter);
76
- return pos !== -1 ? s.substr(pos + 1) : s;
80
+ return pos !== -1 ? s.slice(pos + 1) : s;
77
81
  }
78
82
  exports._substringAfterLast = _substringAfterLast;
79
83
  /**
@@ -32,7 +32,9 @@ export function _removeWhitespace(s) {
32
32
  export function _truncate(s, maxLen, omission = '...') {
33
33
  if (!s || s.length <= maxLen)
34
34
  return s;
35
- return s.substr(0, maxLen - omission.length) + omission;
35
+ if (maxLen <= omission.length)
36
+ return omission;
37
+ return s.slice(0, maxLen - omission.length) + omission;
36
38
  }
37
39
  /**
38
40
  * _.truncateMiddle('abcdefghijklmnopqrstuvwxyz', 10)
@@ -41,26 +43,28 @@ export function _truncate(s, maxLen, omission = '...') {
41
43
  export function _truncateMiddle(s, maxLen, omission = '...') {
42
44
  if (!s || s.length <= maxLen)
43
45
  return s;
46
+ if (maxLen <= omission.length)
47
+ return omission;
44
48
  const mark1 = Math.round((maxLen - omission.length) / 2);
45
49
  const mark2 = s.length - Math.floor((maxLen - omission.length) / 2);
46
- return s.substr(0, mark1) + omission + s.substr(mark2);
50
+ return s.slice(0, mark1) + omission + s.slice(mark2);
47
51
  }
48
52
  // These functions are modeled after Kotlin's String API
49
53
  export function _substringBefore(s, delimiter) {
50
54
  const pos = s.indexOf(delimiter);
51
- return s.substr(0, pos !== -1 ? pos : undefined);
55
+ return s.slice(0, pos !== -1 ? pos : undefined);
52
56
  }
53
57
  export function _substringBeforeLast(s, delimiter) {
54
58
  const pos = s.lastIndexOf(delimiter);
55
- return s.substr(0, pos !== -1 ? pos : undefined);
59
+ return s.slice(0, pos !== -1 ? pos : undefined);
56
60
  }
57
61
  export function _substringAfter(s, delimiter) {
58
62
  const pos = s.indexOf(delimiter);
59
- return pos !== -1 ? s.substr(pos + 1) : s;
63
+ return pos !== -1 ? s.slice(pos + 1) : s;
60
64
  }
61
65
  export function _substringAfterLast(s, delimiter) {
62
66
  const pos = s.lastIndexOf(delimiter);
63
- return pos !== -1 ? s.substr(pos + 1) : s;
67
+ return pos !== -1 ? s.slice(pos + 1) : s;
64
68
  }
65
69
  /**
66
70
  * Returns the substring between LAST `leftDelimiter` and then FIRST `rightDelimiter`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.115.1",
3
+ "version": "14.115.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -36,8 +36,8 @@ export function _removeWhitespace(s: string): string {
36
36
  */
37
37
  export function _truncate(s: string, maxLen: number, omission = '...'): string {
38
38
  if (!s || s.length <= maxLen) return s
39
-
40
- return s.substr(0, maxLen - omission.length) + omission
39
+ if (maxLen <= omission.length) return omission
40
+ return s.slice(0, maxLen - omission.length) + omission
41
41
  }
42
42
 
43
43
  /**
@@ -46,32 +46,33 @@ export function _truncate(s: string, maxLen: number, omission = '...'): string {
46
46
  */
47
47
  export function _truncateMiddle(s: string, maxLen: number, omission = '...'): string {
48
48
  if (!s || s.length <= maxLen) return s
49
+ if (maxLen <= omission.length) return omission
49
50
 
50
51
  const mark1 = Math.round((maxLen - omission.length) / 2)
51
52
  const mark2 = s.length - Math.floor((maxLen - omission.length) / 2)
52
- return s.substr(0, mark1) + omission + s.substr(mark2)
53
+ return s.slice(0, mark1) + omission + s.slice(mark2)
53
54
  }
54
55
 
55
56
  // These functions are modeled after Kotlin's String API
56
57
 
57
58
  export function _substringBefore(s: string, delimiter: string): string {
58
59
  const pos = s.indexOf(delimiter)
59
- return s.substr(0, pos !== -1 ? pos : undefined)
60
+ return s.slice(0, pos !== -1 ? pos : undefined)
60
61
  }
61
62
 
62
63
  export function _substringBeforeLast(s: string, delimiter: string): string {
63
64
  const pos = s.lastIndexOf(delimiter)
64
- return s.substr(0, pos !== -1 ? pos : undefined)
65
+ return s.slice(0, pos !== -1 ? pos : undefined)
65
66
  }
66
67
 
67
68
  export function _substringAfter(s: string, delimiter: string): string {
68
69
  const pos = s.indexOf(delimiter)
69
- return pos !== -1 ? s.substr(pos + 1) : s
70
+ return pos !== -1 ? s.slice(pos + 1) : s
70
71
  }
71
72
 
72
73
  export function _substringAfterLast(s: string, delimiter: string): string {
73
74
  const pos = s.lastIndexOf(delimiter)
74
- return pos !== -1 ? s.substr(pos + 1) : s
75
+ return pos !== -1 ? s.slice(pos + 1) : s
75
76
  }
76
77
 
77
78
  /**