@tempots/std 0.9.2 → 0.9.5

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.
Files changed (82) hide show
  1. package/README.md +3 -0
  2. package/package.json +2 -2
  3. package/dist/arrays.d.ts +0 -49
  4. package/dist/arrays.js +0 -249
  5. package/dist/async-result.d.ts +0 -37
  6. package/dist/async-result.js +0 -75
  7. package/dist/bigint.d.ts +0 -18
  8. package/dist/bigint.js +0 -110
  9. package/dist/booleans.d.ts +0 -23
  10. package/dist/booleans.js +0 -68
  11. package/dist/colors/cmyk.d.ts +0 -21
  12. package/dist/colors/cmyk.js +0 -54
  13. package/dist/colors/convert.d.ts +0 -283
  14. package/dist/colors/convert.js +0 -742
  15. package/dist/colors/hsl.d.ts +0 -24
  16. package/dist/colors/hsl.js +0 -56
  17. package/dist/colors/hsla.d.ts +0 -18
  18. package/dist/colors/hsla.js +0 -35
  19. package/dist/colors/hsluv.d.ts +0 -24
  20. package/dist/colors/hsluv.js +0 -56
  21. package/dist/colors/hsv.d.ts +0 -24
  22. package/dist/colors/hsv.js +0 -54
  23. package/dist/colors/lab.d.ts +0 -24
  24. package/dist/colors/lab.js +0 -54
  25. package/dist/colors/lch.d.ts +0 -19
  26. package/dist/colors/lch.js +0 -44
  27. package/dist/colors/luv.d.ts +0 -19
  28. package/dist/colors/luv.js +0 -45
  29. package/dist/colors/rgb.d.ts +0 -13
  30. package/dist/colors/rgb.js +0 -47
  31. package/dist/colors/rgba.d.ts +0 -12
  32. package/dist/colors/rgba.js +0 -44
  33. package/dist/colors/srgb.d.ts +0 -24
  34. package/dist/colors/srgb.js +0 -51
  35. package/dist/colors/xyz.d.ts +0 -19
  36. package/dist/colors/xyz.js +0 -41
  37. package/dist/edit.d.ts +0 -20
  38. package/dist/edit.js +0 -29
  39. package/dist/equals.d.ts +0 -3
  40. package/dist/equals.js +0 -122
  41. package/dist/functions.d.ts +0 -20
  42. package/dist/functions.js +0 -38
  43. package/dist/json.d.ts +0 -14
  44. package/dist/json.js +0 -33
  45. package/dist/match.d.ts +0 -16
  46. package/dist/match.js +0 -45
  47. package/dist/maybe.d.ts +0 -9
  48. package/dist/maybe.js +0 -25
  49. package/dist/memoize.d.ts +0 -1
  50. package/dist/memoize.js +0 -9
  51. package/dist/newtype.d.ts +0 -28
  52. package/dist/newtype.js +0 -29
  53. package/dist/numbers.d.ts +0 -104
  54. package/dist/numbers.js +0 -183
  55. package/dist/objects.d.ts +0 -9
  56. package/dist/objects.js +0 -33
  57. package/dist/ord.d.ts +0 -19
  58. package/dist/ord.js +0 -73
  59. package/dist/reg-exps.d.ts +0 -10
  60. package/dist/reg-exps.js +0 -43
  61. package/dist/result.d.ts +0 -31
  62. package/dist/result.js +0 -95
  63. package/dist/strings.d.ts +0 -314
  64. package/dist/strings.js +0 -685
  65. package/dist/types/assert.d.ts +0 -12
  66. package/dist/types/assert.js +0 -13
  67. package/dist/types/differentiate.d.ts +0 -13
  68. package/dist/types/differentiate.js +0 -14
  69. package/dist/types/functions.d.ts +0 -22
  70. package/dist/types/functions.js +0 -13
  71. package/dist/types/generic.d.ts +0 -9
  72. package/dist/types/generic.js +0 -13
  73. package/dist/types/objects.d.ts +0 -50
  74. package/dist/types/objects.js +0 -13
  75. package/dist/types/tuples.d.ts +0 -44
  76. package/dist/types/tuples.js +0 -24
  77. package/dist/types/utility.d.ts +0 -2
  78. package/dist/types/utility.js +0 -1
  79. package/dist/uuid.d.ts +0 -13
  80. package/dist/uuid.js +0 -56
  81. package/dist/validation.d.ts +0 -23
  82. package/dist/validation.js +0 -44
package/dist/strings.js DELETED
@@ -1,685 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Licensed under the Apache License, Version 2.0 (the "License")
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- https://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- /**
14
- * Utility functions to manipulate string values.
15
- */
16
- import { Ord } from './ord';
17
- import { range, any, all, fill } from './arrays';
18
- import { map as mapR } from './reg-exps';
19
- /**
20
- * Replaces all occurrances of `placeholder` in `subject` with the value `replacement`.
21
- * @param subject
22
- * @param placeholder
23
- * @param replacement
24
- */
25
- export function replace(subject, placeholder, replacement) {
26
- return subject.split(placeholder).join(replacement);
27
- }
28
- /**
29
- * `after` searches for the first occurrance of `searchFor` and returns the text after that.
30
- * If `searchFor` is not found, an empty string is returned.
31
- */
32
- export function after(value, searchFor) {
33
- const pos = value.indexOf(searchFor);
34
- if (pos < 0)
35
- return '';
36
- else
37
- return value.substring(pos + searchFor.length);
38
- }
39
- /**
40
- * `afterLast` searches for the last occurrance of `searchFor` and returns the text after that.
41
- * If `searchFor` is not found, an empty string is returned.
42
- */
43
- export function afterLast(value, searchFor) {
44
- const pos = value.lastIndexOf(searchFor);
45
- if (pos < 0)
46
- return '';
47
- else
48
- return value.substring(pos + searchFor.length);
49
- }
50
- /**
51
- * `before` searches for the first occurrance of `searchFor` and returns the text before that.
52
- * If `searchFor` is not found, an empty string is returned.
53
- */
54
- export function before(value, searchFor) {
55
- const pos = value.indexOf(searchFor);
56
- if (pos < 0)
57
- return '';
58
- else
59
- return value.substring(0, pos);
60
- }
61
- /**
62
- * `beforeLast` searches for the last occurrance of `searchFor` and returns the text before that.
63
- * If `searchFor` is not found, an empty string is returned.
64
- */
65
- export function beforeLast(value, searchFor) {
66
- const pos = value.lastIndexOf(searchFor);
67
- if (pos < 0)
68
- return '';
69
- else
70
- return value.substring(0, pos);
71
- }
72
- /**
73
- * `capitalize` returns a string with the first character convert to upper case.
74
- */
75
- export function capitalize(s) {
76
- return s.substring(0, 1).toUpperCase() + s.substring(1);
77
- }
78
- const upperMatch = (s) => s.toUpperCase();
79
- /**
80
- * Capitalize the first letter of every word in `value`. If `whiteSpaceOnly` is set to `true`
81
- * the process is limited to whitespace separated words.
82
- */
83
- export function capitalizeWords(value, whiteSpaceOnly = false) {
84
- if (whiteSpaceOnly) {
85
- return mapR(capitalize(value), UCWORDSWS, upperMatch);
86
- }
87
- else {
88
- return mapR(capitalize(value), UCWORDS, upperMatch);
89
- }
90
- }
91
- /**
92
- * Replaces occurrances of `\r\n`, `\n\r`, `\r` with `\n`
93
- */
94
- export function canonicalizeNewlines(value) {
95
- return value.replace(CANONICALIZE_LINES, '\n');
96
- }
97
- /**
98
- * Compares two strings ignoring their case.
99
- */
100
- export function compareCaseInsensitive(a, b) {
101
- if (a == null && b == null)
102
- return 0;
103
- if (a == null)
104
- return -1;
105
- else if (b == null)
106
- return 1;
107
- return compare(a.toLowerCase(), b.toLowerCase());
108
- }
109
- export function endsWith(s, end) {
110
- return s.substring(0, s.length - end.length) === end;
111
- }
112
- export function endsWithCaseInsensitive(s, end) {
113
- return (s.substring(0, s.length - end.length).toLowerCase() === end.toLowerCase());
114
- }
115
- export function startsWith(s, start) {
116
- return s.substring(0, start.length) === start;
117
- }
118
- export function startsWithCaseInsensitive(s, start) {
119
- return s.substring(0, start.length).toLowerCase() === start.toLowerCase();
120
- }
121
- /**
122
- * Compares a string `s` with many `values` and see if one of them matches its end ignoring their case.
123
- */
124
- export function endsWithAnyCaseInsensitive(s, values) {
125
- return endsWithAny(s.toLowerCase(), values.map(v => v.toLowerCase()));
126
- }
127
- /**
128
- * Compares a string `s` with many `values` and see if one of them matches its beginning ignoring their case.
129
- */
130
- export function startsWithAnyCaseInsensitive(s, values) {
131
- return startsWithAny(s.toLowerCase(), values.map(v => v.toLowerCase()));
132
- }
133
- /**
134
- * It cleans up all the whitespaces in the passed `value`. `collapse` does the following:
135
- * - remove trailing/leading whitespaces
136
- * - within the string, it collapses seqeunces of whitespaces into a single space character
137
- * For whitespaces in this description, it is intended to be anything that is matched by the regular expression `\s`.
138
- */
139
- export function collapse(value) {
140
- return value.trim().replace(WSG, ' ');
141
- }
142
- /**
143
- * It compares to string and it returns a negative number if `a` is inferior to `b`, zero if they are the same,
144
- * or otherwise a positive non-sero number.
145
- */
146
- export function compare(a, b) {
147
- return a < b ? -1 : a > b ? 1 : 0;
148
- }
149
- export const order = Ord.fromNumberComparison(compare);
150
- /**
151
- * `contains` returns `true` if `s` contains one or more occurrences of `test` regardless of the text case.
152
- */
153
- export function containsCaseInsensitive(s, test) {
154
- return s.toLowerCase().includes(test.toLowerCase());
155
- }
156
- /**
157
- * `contains` returns `true` if `s` contains one or more occurrences of `test`.
158
- */
159
- export function contains(s, test) {
160
- return s.includes(test);
161
- }
162
- /**
163
- * Return the number of occurances of `test` in `s`.
164
- */
165
- export function count(s, test) {
166
- return s.split(test).length - 1;
167
- }
168
- /**
169
- * `contains` returns `true` if `s` contains any of the strings in `tests` regardless of the text case
170
- */
171
- export function containsAnyCaseInsensitive(s, tests) {
172
- return any(tests, t => containsCaseInsensitive(s, t));
173
- }
174
- /**
175
- * `contains` returns `true` if `s` contains any of the strings in `tests`
176
- */
177
- export function containsAny(s, tests) {
178
- return any(tests, t => contains(s, t));
179
- }
180
- /**
181
- * `contains` returns `true` if `s` contains all of the strings in `tests` regardless of the text case
182
- */
183
- export function containsAllCaseInsensitive(s, tests) {
184
- return all(tests, t => containsCaseInsensitive(s, t));
185
- }
186
- /**
187
- * `contains` returns `true` if `s` contains all of the strings in `tests`
188
- */
189
- export function containsAll(s, tests) {
190
- return all(tests, t => contains(s, t));
191
- }
192
- /**
193
- * `dasherize` replaces all the occurrances of `_` with `-`
194
- */
195
- export function dasherize(s) {
196
- return s.replace('_', '-');
197
- }
198
- /**
199
- * Compares strings `a` and `b` and returns the position where they differ.
200
- * ```ts
201
- * diffIndex('abcdef', 'abc123') // returns 3
202
- * ```
203
- */
204
- export function diffIndex(a, b) {
205
- const min = Math.min(a.length, b.length);
206
- for (let i = 0; i < min; i++) {
207
- if (a.substring(i, i + 1) !== b.substring(i, i + 1))
208
- return i;
209
- }
210
- return min;
211
- }
212
- /**
213
- * `ellipsis` truncates `s` at len `maxlen` replaces the last characters with the content
214
- * of `symbol`.
215
- * ```ts
216
- * ellipsis('tempo is a nice library', 9) // returns 'tempo is …'
217
- * ```
218
- */
219
- export function ellipsis(s, maxlen = 20, symbol = '…') {
220
- const sl = s.length;
221
- const symboll = symbol.length;
222
- if (sl > maxlen) {
223
- if (maxlen < symboll) {
224
- return symbol.substr(symboll - maxlen, maxlen);
225
- }
226
- else {
227
- return s.substr(0, maxlen - symboll) + symbol;
228
- }
229
- }
230
- else
231
- return s;
232
- }
233
- /**
234
- * Same as `ellipsis` but puts the symbol in the middle of the string and not to the end.
235
- * ```ts
236
- * ellipsisMiddle('tempo is a nice library', 18) // returns 'tempo is … library'
237
- * ```
238
- */
239
- export function ellipsisMiddle(s, maxlen = 20, symbol = '…') {
240
- const sl = s.length;
241
- const symboll = symbol.length;
242
- if (sl > maxlen) {
243
- if (maxlen <= symboll) {
244
- return ellipsis(s, maxlen, symbol);
245
- }
246
- const hll = Math.ceil((maxlen - symboll) / 2);
247
- const hlr = Math.floor((maxlen - symboll) / 2);
248
- return s.substr(0, hll) + symbol + s.substr(sl - hlr, hlr);
249
- }
250
- else
251
- return s;
252
- }
253
- /**
254
- * Returns `true` if `s` ends with any of the values in `values`.
255
- */
256
- export function endsWithAny(s, values) {
257
- return any(values, end => endsWith(s, end));
258
- }
259
- /**
260
- * `filter` applies `predicate` character by character to `s` and it returns a filtered
261
- * version of the string.
262
- */
263
- export function filter(s, predicate) {
264
- return toArray(s).filter(predicate).join('');
265
- }
266
- /**
267
- * Same as `filter` but `predicate` operates on integer char codes instead of string characters.
268
- */
269
- export function filterCharcode(s, predicate) {
270
- const codes = toCharcodes(s).filter(predicate);
271
- return codes.map((i) => String.fromCharCode(i)).join('');
272
- }
273
- /**
274
- * `from` searches for the first occurrance of `searchFor` and returns the text from that point on.
275
- * If `searchFor` is not found, an empty string is returned.
276
- */
277
- export function from(value, searchFor) {
278
- const pos = value.indexOf(searchFor);
279
- if (pos < 0)
280
- return '';
281
- else
282
- return value.substring(pos);
283
- }
284
- export function hashCode(value, seed = 0x811c9dc5) {
285
- let hval = seed;
286
- for (let i = 0, l = value.length; i < l; i++) {
287
- hval ^= value.charCodeAt(i);
288
- hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
289
- }
290
- return hval >>> 0;
291
- }
292
- /**
293
- * Returns `true` if `value` is not `null` and contains at least one character.
294
- */
295
- export function hasContent(value) {
296
- return value != null && value.length > 0;
297
- }
298
- /**
299
- * Works the same as `underscore` but also replaces underscores with whitespaces.
300
- */
301
- export function humanize(s) {
302
- return replace(underscore(s), '_', ' ');
303
- }
304
- /**
305
- * Checks if `s` contains only (and at least one) alphabetical characters.
306
- */
307
- export function isAlpha(s) {
308
- return s.length > 0 && !IS_ALPHA.test(s);
309
- }
310
- /**
311
- * `isAlphaNum` returns `true` if the string only contains alpha-numeric characters.
312
- */
313
- export function isAlphaNum(value) {
314
- return ALPHANUM.test(value);
315
- }
316
- export function isBreakingWhitespace(value) {
317
- return !IS_BREAKINGWHITESPACE.test(value);
318
- }
319
- /**
320
- * Returns `true` if the value string is composed of only lower cased characters
321
- * or case neutral characters.
322
- */
323
- export function isLowerCase(value) {
324
- return value.toLowerCase() === value;
325
- }
326
- /**
327
- * Returns `true` if the value string is composed of only upper cased characters
328
- * or case neutral characters.
329
- */
330
- export function isUpperCase(value) {
331
- return value.toUpperCase() === value;
332
- }
333
- /**
334
- * `ifEmpty` returns `value` if it is neither `null` or empty, otherwise it returns `alt`
335
- */
336
- export function ifEmpty(value, alt) {
337
- return value != null && value !== '' ? value : alt;
338
- }
339
- /**
340
- * `isDigitsOnly` returns `true` if the string only contains digits.
341
- */
342
- export function isDigitsOnly(value) {
343
- return DIGITS.test(value);
344
- }
345
- /**
346
- * `isEmpty` returns true if either `value` is null or is an empty string.
347
- */
348
- export function isEmpty(value) {
349
- return value == null || value === '';
350
- }
351
- /**
352
- * Convert first letter in `value` to lower case.
353
- */
354
- export function lowerCaseFirst(value) {
355
- return value.substring(0, 1).toLowerCase() + value.substring(1);
356
- }
357
- /**
358
- * Returns a random substring from the `value` argument. The length of such value is by default `1`.
359
- */
360
- export function random(value, length = 1) {
361
- return value.substring(Math.floor((value.length - length + 1) * Math.random()), length);
362
- }
363
- /**
364
- * Returns a random sampling of the specified length from the seed string.
365
- */
366
- export function randomSequence(alphabet, length) {
367
- return range(length, () => random(alphabet)).join('');
368
- }
369
- /**
370
- * Like `randomSequence`, but automatically uses the base64 sequence as the seed string.
371
- */
372
- export function randomSequence64(length) {
373
- return randomSequence(BASE64_ALPHABET, length);
374
- }
375
- /**
376
- * It maps a string character by character using `callback`.
377
- */
378
- export function map(callback, value) {
379
- return toArray(value).map(callback);
380
- }
381
- /**
382
- * If present, it removes all the occurrences of `toremove` from `value`.
383
- */
384
- export function remove(value, toremove) {
385
- return replace(value, toremove, '');
386
- }
387
- /**
388
- * If present, it removes the `toremove` text from the end of `value`.
389
- */
390
- export function removeAfter(value, toremove) {
391
- return endsWith(value, toremove)
392
- ? value.substring(0, value.length - toremove.length)
393
- : value;
394
- }
395
- /**
396
- * Removes a slice from `index` to `index + length` from `value`.
397
- */
398
- export function removeAt(value, index, length) {
399
- return value.substring(0, index) + value.substring(index + length);
400
- }
401
- /**
402
- * If present, it removes the `toremove` text from the beginning of `value`.
403
- */
404
- export function removeBefore(value, toremove) {
405
- return startsWith(value, toremove) ? value.substring(toremove.length) : value;
406
- }
407
- /**
408
- * If present, it removes the first occurrence of `toremove` from `value`.
409
- */
410
- export function removeOne(value, toremove) {
411
- const pos = value.indexOf(toremove);
412
- if (pos < 0)
413
- return value;
414
- return value.substring(0, pos) + value.substring(pos + toremove.length);
415
- }
416
- /**
417
- * `repeat` builds a new string by repeating the argument `s`, n `times`.
418
- * ```ts
419
- * repeat('Xy', 3) // generates 'XyXyXy'
420
- * ```
421
- */
422
- export function repeat(s, times) {
423
- return fill(times, s).join('');
424
- }
425
- /**
426
- * Returns a new string whose characters are in reverse order.
427
- */
428
- export function reverse(s) {
429
- const arr = toArray(s);
430
- arr.reverse();
431
- return arr.join('');
432
- }
433
- /**
434
- * Converts a string in a quoted string.
435
- */
436
- export function quote(s) {
437
- if (!s.includes('"'))
438
- return '"' + s + '"';
439
- else if (!s.includes("'"))
440
- return "'" + s + "'";
441
- else
442
- return '"' + replace(s, '"', '\\"') + '"';
443
- }
444
- /**
445
- * It only splits on the first occurrance of separator.
446
- */
447
- export function splitOnce(s, separator) {
448
- const pos = s.indexOf(separator);
449
- if (pos < 0)
450
- return [s];
451
- return [s.substring(0, pos), s.substring(pos + separator.length)];
452
- }
453
- /**
454
- * Returns `true` if `s` starts with any of the values in `values`.
455
- */
456
- export function startsWithAny(s, values) {
457
- return any(values, start => s.startsWith(start));
458
- }
459
- /**
460
- * `stripTags` removes any HTML/XML markup from the string leaving only the concatenation
461
- * of the existing text nodes.
462
- */
463
- export function stripTags(s) {
464
- return s.replace(STRIPTAGS, '');
465
- }
466
- /**
467
- * Surrounds a string with the contents of `left` and `right`. If `right` is omitted,
468
- * `left` will be used on both sides
469
- */
470
- export function surround(s, left, right = left) {
471
- return `${left}${s}${right}`;
472
- }
473
- /**
474
- * It transforms a string into an `Array` of characters.
475
- */
476
- export function toArray(s) {
477
- return s.split('');
478
- }
479
- /**
480
- * It transforms a string into an `Array` of char codes in integer format.
481
- */
482
- export function toCharcodes(s) {
483
- return range(s.length, i => s.charCodeAt(i));
484
- }
485
- /**
486
- * Returns an array of `string` whose elements are equally long (using `len`). If the string `s`
487
- * is not exactly divisible by `len` the last element of the array will be shorter.
488
- */
489
- export function toChunks(s, len) {
490
- const chunks = [];
491
- while (s.length > 0) {
492
- chunks.push(s.substr(0, len));
493
- s = s.substr(len, s.length - len);
494
- }
495
- return chunks;
496
- }
497
- /**
498
- * Returns an array of `string` split by line breaks.
499
- */
500
- export function toLines(s) {
501
- return s.split(SPLIT_LINES);
502
- }
503
- /**
504
- * `trimChars` removes from the beginning and the end of the string any character that is present in `charlist`.
505
- */
506
- export function trimChars(value, charlist) {
507
- return trimCharsRight(trimCharsLeft(value, charlist), charlist);
508
- }
509
- /**
510
- * `trimCharsLeft` removes from the beginning of the string any character that is present in `charlist`.
511
- */
512
- export function trimCharsLeft(value, charlist) {
513
- let pos = 0;
514
- for (let i = 0; i < value.length; i++) {
515
- if (contains(charlist, value.charAt(i)))
516
- pos++;
517
- else
518
- break;
519
- }
520
- return value.substring(pos);
521
- }
522
- /**
523
- * `trimCharsRight` removes from the end of the string any character that is present in `charlist`.
524
- */
525
- export function trimCharsRight(value, charlist) {
526
- const len = value.length;
527
- let pos = len;
528
- let i;
529
- for (let j = 0; j < len; j++) {
530
- i = len - j - 1;
531
- if (contains(charlist, value.charAt(i)))
532
- pos = i;
533
- else
534
- break;
535
- }
536
- return value.substring(0, pos);
537
- }
538
- /**
539
- * `underscore` finds UpperCase characters and turns them into LowerCase and prepends them with a whtiespace.
540
- * Sequences of more than one UpperCase character are left untouched.
541
- */
542
- export function underscore(s) {
543
- s = s.replace(/::/g, '/');
544
- s = s.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2');
545
- s = s.replace(/([a-z\d])([A-Z])/g, '$1_$2');
546
- s = s.replace(/-/g, '_');
547
- return s.toLowerCase();
548
- }
549
- /**
550
- * Convert first letter in `value` to upper case.
551
- */
552
- export function upperCaseFirst(value) {
553
- return value.substring(0, 1).toUpperCase() + value.substring(1);
554
- }
555
- /**
556
- * `upTo` searches for the first occurrance of `searchFor` and returns the text up to that point.
557
- * If `searchFor` is not found, the entire string is returned.
558
- */
559
- export function upTo(value, searchFor) {
560
- const pos = value.indexOf(searchFor);
561
- if (pos < 0)
562
- return value;
563
- else
564
- return value.substring(0, pos);
565
- }
566
- /**
567
- * `wrapColumns` splits a long string into lines that are at most `columns` long.
568
- * Words whose length exceeds `columns` are not split.
569
- */
570
- export function wrapColumns(s, columns = 78, indent = '', newline = '\n') {
571
- return s
572
- .split(SPLIT_LINES)
573
- .map(part => wrapLine(part.replace(WSG, ' ').trim(), columns, indent, newline))
574
- .join(newline);
575
- }
576
- export function isSpaceAt(s, pos) {
577
- if (pos < 0 || pos >= s.length)
578
- return false;
579
- const char = s.charCodeAt(pos);
580
- return (char === 9 ||
581
- char === 10 ||
582
- char === 11 ||
583
- char === 12 ||
584
- char === 13 ||
585
- char === 32);
586
- }
587
- export function encodeBase64(s) {
588
- if (typeof Buffer !== 'undefined') {
589
- return Buffer.from(s).toString('base64');
590
- }
591
- else if (typeof btoa !== 'undefined') {
592
- return btoa(s);
593
- }
594
- else {
595
- throw new Error('no implementation provided for base64 encoding');
596
- }
597
- }
598
- export function decodeBase64(s) {
599
- if (typeof Buffer !== 'undefined') {
600
- return Buffer.from(s, 'base64').toString('utf8');
601
- }
602
- else if (typeof atob !== 'undefined') {
603
- return atob(s);
604
- }
605
- else {
606
- throw new Error('no implementation provided for base64 decoding');
607
- }
608
- }
609
- export function wrapLine(s, columns, indent, newline) {
610
- const parts = [];
611
- const len = s.length;
612
- const ilen = indent.length;
613
- let pos = 0;
614
- columns -= ilen;
615
- // eslint-disable-next-line no-constant-condition
616
- while (true) {
617
- if (pos + columns >= len - ilen) {
618
- parts.push(s.substring(pos));
619
- break;
620
- }
621
- let i = 0;
622
- while (!isSpaceAt(s, pos + columns - i) && i < columns)
623
- i++;
624
- if (i === columns) {
625
- // search ahead
626
- i = 0;
627
- while (!isSpaceAt(s, pos + columns + i) && pos + columns + i < len)
628
- i++;
629
- parts.push(s.substring(pos, pos + columns + i));
630
- pos += columns + i + 1;
631
- }
632
- else {
633
- parts.push(s.substring(pos, pos + columns - i));
634
- pos += columns - i + 1;
635
- }
636
- }
637
- return indent + parts.join(newline + indent);
638
- }
639
- export function lpad(s, char, length) {
640
- const diff = length - s.length;
641
- if (diff > 0) {
642
- return repeat(char, diff) + s;
643
- }
644
- else {
645
- return s;
646
- }
647
- }
648
- export function rpad(s, char, length) {
649
- const diff = length - s.length;
650
- if (diff > 0) {
651
- return s + repeat(char, diff);
652
- }
653
- else {
654
- return s;
655
- }
656
- }
657
- export function splitOnLast(s, find) {
658
- const x = s.lastIndexOf(find);
659
- if (x >= 0) {
660
- return [s.substring(0, x), s.substring(x + find.length)];
661
- }
662
- else {
663
- return [s];
664
- }
665
- }
666
- export function splitOnFirst(s, find) {
667
- const x = s.indexOf(find);
668
- if (x >= 0) {
669
- return [s.substring(0, x), s.substring(x + find.length)];
670
- }
671
- else {
672
- return [s];
673
- }
674
- }
675
- const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
676
- const UCWORDS = /[^a-zA-Z]([a-z])/g;
677
- const IS_BREAKINGWHITESPACE = /[^\t\n\r ]/;
678
- const IS_ALPHA = /[^a-zA-Z]/;
679
- const UCWORDSWS = /[ \t\r\n][a-z]/g;
680
- const ALPHANUM = /^[a-z0-9]+$/i;
681
- const DIGITS = /^[0-9]+$/;
682
- const STRIPTAGS = /<\/?[a-z]+[^>]*>/gi;
683
- const WSG = /[ \t\r\n]+/g;
684
- const SPLIT_LINES = /\r\n|\n\r|\n|\r/g;
685
- const CANONICALIZE_LINES = /\r\n|\n\r|\r/g;
@@ -1,12 +0,0 @@
1
- /**
2
- *
3
- */
4
- import { type Pointer } from './generic';
5
- export type Assert<A extends true> = A extends never ? 'FAIL' : A extends true ? 'PASS' : 'FAIL';
6
- export type AssertNot<A extends false> = A extends never ? 'FAIL' : A extends false ? 'PASS' : 'FAIL';
7
- export type Extends<A, B> = A extends B ? true : false;
8
- export type Same<A, B> = Pointer<A> extends Pointer<B> ? Pointer<B> extends Pointer<A> ? true : false : false;
9
- export type NotSame<A, B> = Pointer<A> extends Pointer<B> ? Pointer<B> extends Pointer<A> ? false : true : true;
10
- export type Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
11
- export type NotEquals<A, B> = Equals<A, B> extends true ? false : true;
12
- export type IsNever<T> = Pointer<T> extends Pointer<never> ? true : false;
@@ -1,13 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- https://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
- export {};