@tempots/std 0.9.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.
Files changed (132) hide show
  1. package/dist/arrays.d.ts +49 -0
  2. package/dist/arrays.js +249 -0
  3. package/dist/async-result.d.ts +37 -0
  4. package/dist/async-result.js +75 -0
  5. package/dist/bigint.d.ts +18 -0
  6. package/dist/bigint.js +110 -0
  7. package/dist/booleans.d.ts +23 -0
  8. package/dist/booleans.js +68 -0
  9. package/dist/colors/cmyk.d.ts +21 -0
  10. package/dist/colors/cmyk.js +54 -0
  11. package/dist/colors/convert.d.ts +283 -0
  12. package/dist/colors/convert.js +742 -0
  13. package/dist/colors/hsl.d.ts +24 -0
  14. package/dist/colors/hsl.js +56 -0
  15. package/dist/colors/hsla.d.ts +18 -0
  16. package/dist/colors/hsla.js +35 -0
  17. package/dist/colors/hsluv.d.ts +24 -0
  18. package/dist/colors/hsluv.js +56 -0
  19. package/dist/colors/hsv.d.ts +24 -0
  20. package/dist/colors/hsv.js +54 -0
  21. package/dist/colors/lab.d.ts +24 -0
  22. package/dist/colors/lab.js +54 -0
  23. package/dist/colors/lch.d.ts +19 -0
  24. package/dist/colors/lch.js +44 -0
  25. package/dist/colors/luv.d.ts +19 -0
  26. package/dist/colors/luv.js +45 -0
  27. package/dist/colors/rgb.d.ts +13 -0
  28. package/dist/colors/rgb.js +47 -0
  29. package/dist/colors/rgba.d.ts +12 -0
  30. package/dist/colors/rgba.js +44 -0
  31. package/dist/colors/srgb.d.ts +24 -0
  32. package/dist/colors/srgb.js +51 -0
  33. package/dist/colors/xyz.d.ts +19 -0
  34. package/dist/colors/xyz.js +41 -0
  35. package/dist/edit.d.ts +20 -0
  36. package/dist/edit.js +29 -0
  37. package/dist/equals.d.ts +3 -0
  38. package/dist/equals.js +122 -0
  39. package/dist/functions.d.ts +20 -0
  40. package/dist/functions.js +38 -0
  41. package/dist/json.d.ts +14 -0
  42. package/dist/json.js +33 -0
  43. package/dist/match.d.ts +16 -0
  44. package/dist/match.js +45 -0
  45. package/dist/maybe.d.ts +9 -0
  46. package/dist/maybe.js +25 -0
  47. package/dist/memoize.d.ts +1 -0
  48. package/dist/memoize.js +9 -0
  49. package/dist/newtype.d.ts +28 -0
  50. package/dist/newtype.js +29 -0
  51. package/dist/numbers.d.ts +104 -0
  52. package/dist/numbers.js +183 -0
  53. package/dist/objects.d.ts +9 -0
  54. package/dist/objects.js +33 -0
  55. package/dist/ord.d.ts +19 -0
  56. package/dist/ord.js +73 -0
  57. package/dist/reg-exps.d.ts +10 -0
  58. package/dist/reg-exps.js +43 -0
  59. package/dist/result.d.ts +31 -0
  60. package/dist/result.js +95 -0
  61. package/dist/strings.d.ts +314 -0
  62. package/dist/strings.js +685 -0
  63. package/dist/types/assert.d.ts +12 -0
  64. package/dist/types/assert.js +13 -0
  65. package/dist/types/differentiate.d.ts +13 -0
  66. package/dist/types/differentiate.js +14 -0
  67. package/dist/types/functions.d.ts +22 -0
  68. package/dist/types/functions.js +13 -0
  69. package/dist/types/generic.d.ts +9 -0
  70. package/dist/types/generic.js +13 -0
  71. package/dist/types/objects.d.ts +50 -0
  72. package/dist/types/objects.js +13 -0
  73. package/dist/types/tuples.d.ts +44 -0
  74. package/dist/types/tuples.js +24 -0
  75. package/dist/types/utility.d.ts +2 -0
  76. package/dist/types/utility.js +1 -0
  77. package/dist/uuid.d.ts +13 -0
  78. package/dist/uuid.js +56 -0
  79. package/dist/validation.d.ts +23 -0
  80. package/dist/validation.js +44 -0
  81. package/package.json +36 -0
  82. package/src/arrays.ts +296 -0
  83. package/src/async-result.ts +103 -0
  84. package/src/bigint.ts +111 -0
  85. package/src/booleans.ts +73 -0
  86. package/src/colors/cmyk.ts +84 -0
  87. package/src/colors/convert.ts +1093 -0
  88. package/src/colors/hsl.ts +73 -0
  89. package/src/colors/hsla.ts +45 -0
  90. package/src/colors/hsluv.ts +73 -0
  91. package/src/colors/hsv.ts +75 -0
  92. package/src/colors/lab.ts +69 -0
  93. package/src/colors/lch.ts +53 -0
  94. package/src/colors/luv.ts +56 -0
  95. package/src/colors/rgb.ts +55 -0
  96. package/src/colors/rgba.ts +53 -0
  97. package/src/colors/srgb.ts +72 -0
  98. package/src/colors/xyz.ts +52 -0
  99. package/src/edit.ts +29 -0
  100. package/src/equals.ts +116 -0
  101. package/src/functions.ts +108 -0
  102. package/src/json.ts +52 -0
  103. package/src/match.ts +88 -0
  104. package/src/maybe.ts +32 -0
  105. package/src/memoize.ts +9 -0
  106. package/src/newtype.ts +59 -0
  107. package/src/numbers.ts +222 -0
  108. package/src/objects.ts +47 -0
  109. package/src/ord.ts +79 -0
  110. package/src/reg-exps.ts +48 -0
  111. package/src/result.ts +140 -0
  112. package/src/strings.ts +768 -0
  113. package/src/types/assert.ts +96 -0
  114. package/src/types/differentiate.ts +89 -0
  115. package/src/types/functions.ts +114 -0
  116. package/src/types/generic.ts +42 -0
  117. package/src/types/objects.ts +212 -0
  118. package/src/types/tuples.ts +244 -0
  119. package/src/types/utility.ts +3 -0
  120. package/src/uuid.ts +61 -0
  121. package/src/validation.ts +69 -0
  122. package/test/arrays.spec.ts +410 -0
  123. package/test/colors.spec.ts +406 -0
  124. package/test/commmon.ts +9 -0
  125. package/test/equals.spec.ts +165 -0
  126. package/test/functions.spec.ts +9 -0
  127. package/test/index.d.ts +20 -0
  128. package/test/objects.spec.ts +22 -0
  129. package/test/reg-exps.spec.ts +33 -0
  130. package/test/strings.spec.ts +333 -0
  131. package/test/uuid.spec.ts +35 -0
  132. package/tsconfig.json +19 -0
@@ -0,0 +1,333 @@
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
+ import { describe, expect, test } from 'vitest'
15
+ import { Ordering } from '../src/ord'
16
+ import {
17
+ lowerCaseFirst,
18
+ upperCaseFirst,
19
+ contains,
20
+ count,
21
+ containsAny,
22
+ containsAll,
23
+ hashCode,
24
+ capitalizeWords,
25
+ diffIndex,
26
+ ellipsis,
27
+ ellipsisMiddle,
28
+ isAlphaNum,
29
+ humanize,
30
+ wrapColumns,
31
+ repeat,
32
+ upTo,
33
+ from,
34
+ after,
35
+ stripTags,
36
+ trimCharsLeft,
37
+ trimCharsRight,
38
+ trimChars,
39
+ toArray,
40
+ toLines,
41
+ order,
42
+ reverse
43
+ } from '../src/strings'
44
+
45
+ describe('strings.ts', () => {
46
+ test('LowerUpperCaseFirst', () => {
47
+ expect('aBC').toBe(lowerCaseFirst('ABC'))
48
+ expect('Abc').toBe(upperCaseFirst('abc'))
49
+ })
50
+
51
+ test('Contains', () => {
52
+ expect(contains('test', '')).toBe(true)
53
+ expect(contains('test', 't')).toBe(true)
54
+ expect(contains('test', 'te')).toBe(true)
55
+ expect(contains('test', 'tes')).toBe(true)
56
+ expect(contains('test', 'test')).toBe(true)
57
+ expect(contains('one two three', 'one')).toBe(true)
58
+ expect(contains('one two three', 'two')).toBe(true)
59
+ expect(contains('one two three', 'three')).toBe(true)
60
+ expect(contains('test', 'test ')).toBe(false)
61
+ expect(contains('test', ' test')).toBe(false)
62
+ expect(contains('test', 'tes ')).toBe(false)
63
+ })
64
+
65
+ test('Count', () => {
66
+ expect(3).toBe(
67
+ count('one two three four five six seven eight nine ten', 'o')
68
+ )
69
+ expect(2).toBe(
70
+ count('one two three four five six seven eight nine ten', 'en')
71
+ )
72
+ expect(3).toBe(
73
+ count('one two three four five six seven eight nine ten', ' t')
74
+ )
75
+ expect(2).toBe(
76
+ count('one two three four five six seven eight nine ten', 've')
77
+ )
78
+ expect(0).toBe(count('xxxxxx', 'y'))
79
+ expect(6).toBe(count('xxxxxx', 'x'))
80
+ expect(3).toBe(count('xxxxxx', 'xx'))
81
+ expect(2).toBe(count('xxxxxx', 'xxx'))
82
+ expect(1).toBe(count('xxxxxx', 'xxxx'))
83
+ expect(0).toBe(count('x', 'xx'))
84
+ })
85
+
86
+ test('ContainsAny', () => {
87
+ expect(containsAny('test', ['t', 'x', 'y'])).toBe(true)
88
+ expect(containsAny('test', ['e', 'x', 'y'])).toBe(true)
89
+ expect(containsAny('test', ['s', 'x', 'y'])).toBe(true)
90
+ expect(containsAny('test', ['x', 't', 'y'])).toBe(true)
91
+ expect(containsAny('test', ['x', 'e', 'y'])).toBe(true)
92
+ expect(containsAny('test', ['x', 's', 'y'])).toBe(true)
93
+ expect(containsAny('test', ['x', 'y', 't'])).toBe(true)
94
+ expect(containsAny('test', ['x', 'y', 'e'])).toBe(true)
95
+ expect(containsAny('test', ['x', 'y', 's'])).toBe(true)
96
+ expect(containsAny('one two three', ['zero', 'one', 'two'])).toBe(true)
97
+ expect(containsAny('one two three', ['one', 'two', 'three'])).toBe(true)
98
+ expect(containsAny('one two three', ['one two', 'x', 'three'])).toBe(true)
99
+ })
100
+
101
+ test('ContainsAll', () => {
102
+ expect(containsAll('test', ['t', 's', 'e'])).toBe(true)
103
+ expect(containsAll('test', ['e', 'x', 'y'])).toBe(false)
104
+ expect(containsAll('test', ['t'])).toBe(true)
105
+ expect(containsAll('test', ['e'])).toBe(true)
106
+ expect(containsAll('test', ['s', 't'])).toBe(true)
107
+ expect(containsAll('test', ['x', 't'])).toBe(false)
108
+ expect(containsAll('one two three', ['zero', 'one', 'two'])).toBe(false)
109
+ expect(containsAll('one two three', ['one', 'two', 'three'])).toBe(true)
110
+ expect(containsAll('one two three', ['one two', 'three'])).toBe(true)
111
+ })
112
+
113
+ test('HashCode', () => {
114
+ expect(hashCode('a')).toBe(3826002220)
115
+ expect(hashCode('abc')).toBe(440920331)
116
+ expect(hashCode('abcdefghijklm')).toBe(998463208)
117
+ expect(hashCode('abcdefghijklM')).toBe(461579400)
118
+ expect(hashCode('Abcdefghijklm')).toBe(3054447752)
119
+ expect(
120
+ hashCode(
121
+ 'abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklm!!'
122
+ )
123
+ ).toBe(3846459698)
124
+ })
125
+
126
+ test('Ucwordsws', () => {
127
+ const tests = [
128
+ { expected: 'Test', test: 'test' },
129
+ { expected: 'Test Test', test: 'test test' },
130
+ { expected: ' Test Test Test ', test: ' test test test ' },
131
+ { expected: 'Test\nTest', test: 'test\ntest' },
132
+ { expected: 'Test\tTest', test: 'test\ttest' }
133
+ ]
134
+ for (const item of tests) { expect(capitalizeWords(item.test, true)).toBe(item.expected) }
135
+ })
136
+
137
+ test('diffIndex', () => {
138
+ expect(3).toBe(diffIndex('abcdef', 'abc123'))
139
+ expect(0).toBe(diffIndex('', 'abc123'))
140
+ expect(1).toBe(diffIndex('a', 'abc123'))
141
+ expect(0).toBe(diffIndex('abc123', ''))
142
+ expect(1).toBe(diffIndex('abc123', 'a'))
143
+ })
144
+
145
+ test('Ellipsis', () => {
146
+ const test = 'abcdefghijkl'
147
+ const tests = [
148
+ { expected: 'abcdefghijkl', len: undefined, symbol: undefined },
149
+ { expected: 'abcdefghijkl', len: 100, symbol: undefined },
150
+ { expected: 'abcd…', len: 5, symbol: undefined },
151
+ { expected: 'a ...', len: 5, symbol: ' ...' },
152
+ { expected: '..', len: 2, symbol: ' ...' },
153
+ { expected: 'abcdef ...', len: 10, symbol: ' ...' }
154
+ ]
155
+ for (const item of tests) { expect(item.expected).toBe(ellipsis(test, item.len, item.symbol)) }
156
+ })
157
+
158
+ test('EllipsisMiddle', () => {
159
+ const test = 'abcdefghijkl'
160
+ const tests = [
161
+ { expected: 'abcdefghijkl', len: undefined, symbol: undefined },
162
+ { expected: 'abcdefghijkl', len: 100, symbol: undefined },
163
+ { expected: 'ab…kl', len: 5, symbol: undefined },
164
+ { expected: 'a ...', len: 5, symbol: ' ...' },
165
+ { expected: '..', len: 2, symbol: ' ...' },
166
+ { expected: 'abc ...jkl', len: 10, symbol: ' ...' }
167
+ ]
168
+ for (const item of tests) { expect(item.expected).toBe(ellipsisMiddle(test, item.len, item.symbol)) }
169
+ })
170
+
171
+ test('Ucwords', () => {
172
+ const tests = [
173
+ { expected: 'Test', test: 'test' },
174
+ { expected: 'Test Test', test: 'test test' },
175
+ {
176
+ expected: ' Test-Test:Test_Test : Test ',
177
+ test: ' test-test:test_test : test '
178
+ },
179
+ { expected: 'Test\nTest', test: 'test\ntest' },
180
+ { expected: 'Test\tTest', test: 'test\ttest' }
181
+ ]
182
+ for (const item of tests) { expect(capitalizeWords(item.test)).toBe(item.expected) }
183
+ })
184
+
185
+ test('AlphaNum', () => {
186
+ const tests = [
187
+ { expected: true, test: 'a' },
188
+ { expected: true, test: '1a' },
189
+ { expected: false, test: ' a' },
190
+ { expected: false, test: ' ' },
191
+ { expected: false, test: '' }
192
+ ]
193
+ for (const item of tests) expect(item.expected).toBe(isAlphaNum(item.test))
194
+ })
195
+
196
+ test('Humanize', () => {
197
+ expect(humanize('helloWorld')).toBe('hello world')
198
+ expect(humanize('my_long_string')).toBe('my long string')
199
+ expect(humanize('ignoreMANY')).toBe('ignore many')
200
+ })
201
+
202
+ test('WrapColumn', () => {
203
+ const text =
204
+ 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
205
+
206
+ expect(
207
+ `Lorem ipsum dolor
208
+ sit amet,
209
+ consectetur
210
+ adipisicing elit,
211
+ sed do eiusmod
212
+ tempor incididunt ut
213
+ labore et dolore
214
+ magna aliqua. Ut
215
+ enim ad minim
216
+ veniam, quis nostrud
217
+ exercitation ullamco
218
+ laboris nisi ut
219
+ aliquip ex ea
220
+ commodo consequat.`
221
+ ).toBe(wrapColumns(text, 20))
222
+
223
+ expect(
224
+ ` Lorem ipsum
225
+ dolor sit amet,
226
+ consectetur
227
+ adipisicing
228
+ elit, sed do
229
+ eiusmod tempor
230
+ incididunt ut
231
+ labore et dolore
232
+ magna aliqua. Ut
233
+ enim ad minim
234
+ veniam, quis
235
+ nostrud
236
+ exercitation
237
+ ullamco laboris
238
+ nisi ut aliquip
239
+ ex ea commodo
240
+ consequat.`
241
+ ).toBe(wrapColumns(text, 20, ' '))
242
+ })
243
+
244
+ test('WrapColumnPreserveNewLines', () => {
245
+ const text = 'Lorem ipsum dolor sit amet,\n\nconsectetur adipisicing elit'
246
+ expect(
247
+ 'Lorem ipsum dolor\nsit amet,\n\nconsectetur\nadipisicing elit'
248
+ ).toBe(wrapColumns(text, 18))
249
+ })
250
+
251
+ test('WrapColumnLong', () => {
252
+ const text = 'aaaaaaaaaa aaaa aaa aa'
253
+ expect(
254
+ `aaaaaaaaaa
255
+ aaaa
256
+ aaa aa`
257
+ ).toBe(wrapColumns(text, 6))
258
+ })
259
+
260
+ test('Repeat', () => {
261
+ expect('XyXyXy').toBe(repeat('Xy', 3))
262
+ })
263
+
264
+ test('UpTo', () => {
265
+ expect('abcdef').toBe(upTo('abcdef', 'x'))
266
+ expect('ab').toBe(upTo('abcdef', 'cd'))
267
+ })
268
+
269
+ test('From', () => {
270
+ expect('').toBe(from('abcdef', 'x'))
271
+ expect('cdef').toBe(from('abcdef', 'cd'))
272
+ })
273
+
274
+ test('After', () => {
275
+ expect('').toBe(after('abcdef', 'x'))
276
+ expect('ef').toBe(after('abcdef', 'cd'))
277
+ })
278
+
279
+ test('StripTags', () => {
280
+ expect('a code; x').toBe(
281
+ stripTags('a<br/> <script src="aaa">code;</script> x')
282
+ )
283
+ })
284
+
285
+ test('Ltrim', () => {
286
+ expect('abcde').toBe(trimCharsLeft('abcde', 'x'))
287
+ expect('de').toBe(trimCharsLeft('abcde', 'cba'))
288
+ expect('abcde').toBe(trimCharsLeft('abcde', 'b'))
289
+
290
+ expect('').toBe(trimCharsLeft('/', '/'))
291
+ })
292
+
293
+ test('Rtrim', () => {
294
+ expect('abcde').toBe(trimCharsRight('abcde', 'x'))
295
+ expect('ab').toBe(trimCharsRight('abcde', 'ced'))
296
+ expect('abcde').toBe(trimCharsRight('abcde', 'd'))
297
+
298
+ expect('').toBe(trimCharsRight('/', '/'))
299
+ })
300
+
301
+ test('Trim', () => {
302
+ expect('abcde').toBe(trimChars('abcde', 'x'))
303
+ expect('cd').toBe(trimChars('abcde', 'abe'))
304
+ expect('abcde').toBe(trimChars('abcde', 'bd'))
305
+
306
+ expect('').toBe(trimChars('/', '/'))
307
+ })
308
+
309
+ test('ToArray', () => {
310
+ const t = 'a☺b☺☺c☺☺☺'
311
+ const e = ['a', '☺', 'b', '☺', '☺', 'c', '☺', '☺', '☺']
312
+ expect(e).toEqual(toArray(t))
313
+ })
314
+
315
+ test('ToLines', () => {
316
+ const text = `Split
317
+ to
318
+ lines`
319
+ expect(['Split', 'to', 'lines']).toEqual(toLines(text))
320
+ })
321
+
322
+ test('Reverse', () => {
323
+ const t = 'a☺b☺☺c☺☺☺'
324
+ const e = '☺☺☺c☺☺b☺a'
325
+ expect(e).toEqual(reverse(t))
326
+ })
327
+
328
+ test('Order', () => {
329
+ expect(Ordering.EQ).toBe(order.compare('companyId', 'companyId'))
330
+ expect(Ordering.LT).toBe(order.compare('companyIc', 'companyId'))
331
+ expect(Ordering.GT).toBe(order.compare('companyId', 'companyIc'))
332
+ })
333
+ })
@@ -0,0 +1,35 @@
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
+ import { describe, expect, test } from 'vitest'
15
+ import { create, UUID } from '../src/uuid'
16
+
17
+ describe('UUID', () => {
18
+ test('validate random created UUIDS', () => {
19
+ for (let i = 0; i < 1000; i++) {
20
+ expect(UUID.isValid(UUID.get(create()))).toBe(true)
21
+ }
22
+ })
23
+
24
+ test('validate random created UUIDS', () => {
25
+ expect(UUID.isValid('43f0a658-70ee-4ab8-8c6d-7f959141115e')).toBe(true)
26
+
27
+ expect(UUID.isValid('some-value')).toBe(false)
28
+ expect(UUID.isValid('-6b909adc-d628-411a-8894-16cfdd296073')).toBe(false)
29
+ expect(UUID.isValid('6b909adc-d628-411a-8894-16cfdd296073-')).toBe(false)
30
+ expect(UUID.isValid('a6b909adc-d628-411a-8894-16cfdd296073')).toBe(false)
31
+ expect(UUID.isValid('6b909adc-d628-411a-8894-16cfdd2960732')).toBe(false)
32
+ expect(UUID.isValid('aaaaaaaa-0000-3333-8888-1111111111111')).toBe(false)
33
+ expect(UUID.isValid('aaaaaaaa-0000-4333-1888-1111111111111')).toBe(false)
34
+ })
35
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "outDir": "dist",
5
+ "target": "ESNext",
6
+ "declaration": true,
7
+ "useDefineForClassFields": true,
8
+ "module": "ESNext",
9
+ "lib": ["ESNext", "DOM"],
10
+ "moduleResolution": "Node",
11
+ "strict": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "esModuleInterop": true,
15
+ "noImplicitReturns": true,
16
+ "skipLibCheck": true
17
+ },
18
+ "include": ["src/**/*"]
19
+ }