@bessemer/cornerstone 0.5.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.
- package/jest.config.js +3 -0
- package/package.json +39 -0
- package/src/array.ts +142 -0
- package/src/async.ts +114 -0
- package/src/cache.ts +236 -0
- package/src/combinable.ts +40 -0
- package/src/comparator.ts +78 -0
- package/src/content.ts +138 -0
- package/src/context.ts +6 -0
- package/src/crypto.ts +11 -0
- package/src/date.ts +18 -0
- package/src/duration.ts +57 -0
- package/src/either.ts +29 -0
- package/src/entry.ts +21 -0
- package/src/equalitor.ts +12 -0
- package/src/error-event.ts +126 -0
- package/src/error.ts +16 -0
- package/src/expression/array-expression.ts +29 -0
- package/src/expression/expression-evaluator.ts +34 -0
- package/src/expression/expression.ts +188 -0
- package/src/expression/internal.ts +34 -0
- package/src/expression/numeric-expression.ts +182 -0
- package/src/expression/string-expression.ts +38 -0
- package/src/expression.ts +48 -0
- package/src/function.ts +3 -0
- package/src/glob.ts +19 -0
- package/src/global-variable.ts +40 -0
- package/src/hash.ts +28 -0
- package/src/hex-code.ts +6 -0
- package/src/index.ts +82 -0
- package/src/lazy.ts +11 -0
- package/src/logger.ts +144 -0
- package/src/math.ts +132 -0
- package/src/misc.ts +22 -0
- package/src/object.ts +236 -0
- package/src/patch.ts +128 -0
- package/src/precondition.ts +25 -0
- package/src/promise.ts +16 -0
- package/src/property.ts +29 -0
- package/src/reference.ts +68 -0
- package/src/resource.ts +32 -0
- package/src/result.ts +66 -0
- package/src/retry.ts +70 -0
- package/src/rich-text.ts +24 -0
- package/src/set.ts +46 -0
- package/src/signature.ts +20 -0
- package/src/store.ts +91 -0
- package/src/string.ts +173 -0
- package/src/tag.ts +68 -0
- package/src/types.ts +21 -0
- package/src/ulid.ts +28 -0
- package/src/unit.ts +4 -0
- package/src/uri.ts +321 -0
- package/src/url.ts +155 -0
- package/src/uuid.ts +37 -0
- package/src/zod.ts +24 -0
- package/test/comparator.test.ts +1 -0
- package/test/expression.test.ts +12 -0
- package/test/object.test.ts +104 -0
- package/test/patch.test.ts +170 -0
- package/test/set.test.ts +20 -0
- package/test/string.test.ts +22 -0
- package/test/uri.test.ts +111 -0
- package/test/url.test.ts +174 -0
- package/tsconfig.build.json +13 -0
- package/tsup.config.ts +4 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
import { Objects } from '@bessemer/cornerstone'
|
2
|
+
|
3
|
+
test('Objects.mergeAll', () => {
|
4
|
+
expect(
|
5
|
+
Objects.mergeAll([
|
6
|
+
{ one: 'First Value', two: 'Second Value', three: 'First Value' },
|
7
|
+
{ one: 'Update Value' },
|
8
|
+
{ one: 'Update Value 2', two: null, four: 'Fourth Value' },
|
9
|
+
{ three: undefined },
|
10
|
+
])
|
11
|
+
).toEqual({
|
12
|
+
one: 'Update Value 2',
|
13
|
+
two: null,
|
14
|
+
three: 'First Value',
|
15
|
+
four: 'Fourth Value',
|
16
|
+
})
|
17
|
+
})
|
18
|
+
|
19
|
+
test('Objects.parsePath', () => {
|
20
|
+
expect(Objects.parsePath('')).toEqual(Objects.path([]))
|
21
|
+
expect(Objects.parsePath('this')).toEqual(Objects.path(['this']))
|
22
|
+
expect(Objects.parsePath('this.is[2].a.path')).toEqual(Objects.path(['this', 'is', 2, 'a', 'path']))
|
23
|
+
expect(Objects.parsePath('this.is[2].a.path[1]')).toEqual(Objects.path(['this', 'is', 2, 'a', 'path', 1]))
|
24
|
+
})
|
25
|
+
|
26
|
+
type Address = {
|
27
|
+
addressLine1: string
|
28
|
+
addressLine2: string | null
|
29
|
+
postcode?: number
|
30
|
+
}
|
31
|
+
|
32
|
+
type Location = {
|
33
|
+
name: string
|
34
|
+
address: Address
|
35
|
+
}
|
36
|
+
|
37
|
+
type Person = {
|
38
|
+
id: number
|
39
|
+
name: string
|
40
|
+
age: number
|
41
|
+
pets: Array<string>
|
42
|
+
primaryAddress: Address
|
43
|
+
residences: Array<Location>
|
44
|
+
}
|
45
|
+
|
46
|
+
const person: Person = {
|
47
|
+
id: 1234,
|
48
|
+
name: 'Bob Bobson',
|
49
|
+
age: 30,
|
50
|
+
pets: ['Fishy Fish', 'Yogi', 'General Bismark'],
|
51
|
+
primaryAddress: {
|
52
|
+
addressLine1: '123 Fake Street.',
|
53
|
+
addressLine2: 'Apt 6',
|
54
|
+
postcode: 77586,
|
55
|
+
},
|
56
|
+
residences: [
|
57
|
+
{
|
58
|
+
name: 'Winter Estate',
|
59
|
+
address: {
|
60
|
+
addressLine1: 'Siberia',
|
61
|
+
addressLine2: null,
|
62
|
+
postcode: 34534,
|
63
|
+
},
|
64
|
+
},
|
65
|
+
{
|
66
|
+
name: 'Summer Palace',
|
67
|
+
address: {
|
68
|
+
addressLine1: '456 Palace Avenue',
|
69
|
+
addressLine2: null,
|
70
|
+
},
|
71
|
+
},
|
72
|
+
],
|
73
|
+
}
|
74
|
+
|
75
|
+
test('Objects.getPathValue', () => {
|
76
|
+
expect(Objects.getPathValue(person, 'id')).toEqual(1234)
|
77
|
+
expect(Objects.getPathValue(person, 'pets[1]')).toEqual('Yogi')
|
78
|
+
expect(Objects.getPathValue(person, 'primaryAddress.addressLine1')).toEqual('123 Fake Street.')
|
79
|
+
expect(Objects.getPathValue(person, 'residences[0].address')).toEqual({
|
80
|
+
addressLine1: 'Siberia',
|
81
|
+
addressLine2: null,
|
82
|
+
postcode: 34534,
|
83
|
+
})
|
84
|
+
expect(Objects.getPathValue(person, 'residences[2].address')).toEqual(undefined)
|
85
|
+
expect(Objects.getPathValue(person, 'residences.address[0]')).toEqual(undefined)
|
86
|
+
})
|
87
|
+
|
88
|
+
test('Objects.applyPathValue', () => {
|
89
|
+
{
|
90
|
+
const modifiedPerson = Objects.applyPathValue(person, 'primaryAddress.addressLine1', 'Changed!') as Person
|
91
|
+
expect(modifiedPerson.primaryAddress.addressLine1).toEqual('Changed!')
|
92
|
+
expect(person.primaryAddress.addressLine1).toEqual('123 Fake Street.')
|
93
|
+
}
|
94
|
+
|
95
|
+
{
|
96
|
+
const modifiedPerson = Objects.applyPathValue(person, 'residences[0].address', 'Changed!') as Person
|
97
|
+
expect(modifiedPerson.residences[0]!.address).toEqual('Changed!')
|
98
|
+
}
|
99
|
+
|
100
|
+
{
|
101
|
+
const modifiedPerson = Objects.applyPathValue(person, 'residences[3].address', 'Changed!') as Person
|
102
|
+
expect(modifiedPerson).toEqual(undefined)
|
103
|
+
}
|
104
|
+
})
|
@@ -0,0 +1,170 @@
|
|
1
|
+
import { Patches } from '@bessemer/cornerstone'
|
2
|
+
import { Expressions } from '@bessemer/cornerstone/expression'
|
3
|
+
|
4
|
+
test('Patch Numbers', () => {
|
5
|
+
{
|
6
|
+
const value = Patches.resolve(5, [Patches.sum(1), Patches.sum(2), Patches.sum(3)], Expressions.defaultEvaluator())
|
7
|
+
expect(value).toEqual(11)
|
8
|
+
}
|
9
|
+
|
10
|
+
{
|
11
|
+
const value = Patches.resolve(5, [Patches.multiply(2), Patches.sum(2), Patches.multiply(2)], Expressions.defaultEvaluator())
|
12
|
+
expect(value).toEqual(24)
|
13
|
+
}
|
14
|
+
|
15
|
+
{
|
16
|
+
const value = Patches.resolve(5, [Patches.set(2), Patches.sum(2), Patches.set(5)], Expressions.defaultEvaluator())
|
17
|
+
expect(value).toEqual(5)
|
18
|
+
}
|
19
|
+
})
|
20
|
+
|
21
|
+
test('Patch Objects', () => {
|
22
|
+
type Address = {
|
23
|
+
addressLine1: string
|
24
|
+
addressLine2: string | null
|
25
|
+
postcode?: number
|
26
|
+
}
|
27
|
+
|
28
|
+
type Location = {
|
29
|
+
name: string
|
30
|
+
address: Address
|
31
|
+
}
|
32
|
+
|
33
|
+
type Person = {
|
34
|
+
id: number
|
35
|
+
name: string
|
36
|
+
age: number
|
37
|
+
pets: Array<string>
|
38
|
+
primaryAddress: Address
|
39
|
+
residences: Array<Location>
|
40
|
+
}
|
41
|
+
|
42
|
+
const originalPerson: Person = {
|
43
|
+
id: 1234,
|
44
|
+
name: 'Bob Bobson',
|
45
|
+
age: 30,
|
46
|
+
pets: ['Fishy Fish', 'Yogi', 'General Bismark'],
|
47
|
+
primaryAddress: {
|
48
|
+
addressLine1: '123 Fake Street.',
|
49
|
+
addressLine2: 'Apt 6',
|
50
|
+
postcode: 77586,
|
51
|
+
},
|
52
|
+
residences: [
|
53
|
+
{
|
54
|
+
name: 'Winter Estate',
|
55
|
+
address: {
|
56
|
+
addressLine1: 'Siberia',
|
57
|
+
addressLine2: null,
|
58
|
+
postcode: 34534,
|
59
|
+
},
|
60
|
+
},
|
61
|
+
{
|
62
|
+
name: 'Summer Palace',
|
63
|
+
address: {
|
64
|
+
addressLine1: '456 Palace Avenue',
|
65
|
+
addressLine2: null,
|
66
|
+
},
|
67
|
+
},
|
68
|
+
],
|
69
|
+
}
|
70
|
+
|
71
|
+
{
|
72
|
+
const updatedPerson = Patches.resolve(
|
73
|
+
originalPerson,
|
74
|
+
[
|
75
|
+
Patches.patch({
|
76
|
+
name: 'Bobby',
|
77
|
+
age: Patches.multiply(2),
|
78
|
+
pets: Patches.set(['Burly Bear']),
|
79
|
+
primaryAddress: {
|
80
|
+
addressLine2: 'New Apartment',
|
81
|
+
},
|
82
|
+
}),
|
83
|
+
],
|
84
|
+
Expressions.defaultEvaluator()
|
85
|
+
)
|
86
|
+
|
87
|
+
expect(originalPerson.name).toEqual('Bob Bobson')
|
88
|
+
expect(updatedPerson.id).toEqual(originalPerson.id)
|
89
|
+
expect(updatedPerson.primaryAddress.addressLine1).toEqual(originalPerson.primaryAddress.addressLine1)
|
90
|
+
|
91
|
+
expect(updatedPerson.name).toEqual('Bobby')
|
92
|
+
expect(updatedPerson.age).toEqual(60)
|
93
|
+
expect(updatedPerson.primaryAddress.addressLine2).toEqual('New Apartment')
|
94
|
+
expect(updatedPerson.pets).toEqual(['Burly Bear'])
|
95
|
+
}
|
96
|
+
|
97
|
+
{
|
98
|
+
const updatedPerson = Patches.resolve(
|
99
|
+
originalPerson,
|
100
|
+
[
|
101
|
+
Patches.patch({
|
102
|
+
pets: Patches.concatenate(['Burly Bear']),
|
103
|
+
primaryAddress: Patches.set({
|
104
|
+
addressLine1: 'Another Street',
|
105
|
+
addressLine2: 'Apt 7',
|
106
|
+
}),
|
107
|
+
}),
|
108
|
+
],
|
109
|
+
Expressions.defaultEvaluator()
|
110
|
+
)
|
111
|
+
|
112
|
+
expect(updatedPerson.pets).toEqual([...originalPerson.pets, 'Burly Bear'])
|
113
|
+
expect(updatedPerson.primaryAddress).toEqual({
|
114
|
+
addressLine1: 'Another Street',
|
115
|
+
addressLine2: 'Apt 7',
|
116
|
+
})
|
117
|
+
}
|
118
|
+
|
119
|
+
{
|
120
|
+
const updatedPerson = Patches.resolve(
|
121
|
+
originalPerson,
|
122
|
+
[
|
123
|
+
Patches.patch({
|
124
|
+
residences: [
|
125
|
+
{
|
126
|
+
name: 'Winter Chalet',
|
127
|
+
},
|
128
|
+
{
|
129
|
+
address: {
|
130
|
+
addressLine1: 'Address Line 1 Changed!',
|
131
|
+
},
|
132
|
+
},
|
133
|
+
],
|
134
|
+
}),
|
135
|
+
],
|
136
|
+
Expressions.defaultEvaluator()
|
137
|
+
)
|
138
|
+
|
139
|
+
expect(updatedPerson.residences.length).toEqual(2)
|
140
|
+
expect(updatedPerson.residences[0]!.name).toEqual('Winter Chalet')
|
141
|
+
expect(updatedPerson.residences[0]!.address.addressLine1).toEqual('Siberia')
|
142
|
+
expect(updatedPerson.residences[1]!.name).toEqual('Summer Palace')
|
143
|
+
expect(updatedPerson.residences[1]!.address.addressLine1).toEqual('Address Line 1 Changed!')
|
144
|
+
}
|
145
|
+
|
146
|
+
{
|
147
|
+
const updatedPerson = Patches.resolve(
|
148
|
+
originalPerson,
|
149
|
+
[
|
150
|
+
Patches.patch({
|
151
|
+
residences: [
|
152
|
+
{},
|
153
|
+
{
|
154
|
+
address: Patches.set({
|
155
|
+
addressLine1: 'Liberia',
|
156
|
+
addressLine2: null,
|
157
|
+
}),
|
158
|
+
},
|
159
|
+
],
|
160
|
+
}),
|
161
|
+
],
|
162
|
+
Expressions.defaultEvaluator()
|
163
|
+
)
|
164
|
+
|
165
|
+
expect(updatedPerson.residences[1]!.address).toEqual({
|
166
|
+
addressLine1: 'Liberia',
|
167
|
+
addressLine2: null,
|
168
|
+
})
|
169
|
+
}
|
170
|
+
})
|
package/test/set.test.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Sets } from '@bessemer/cornerstone'
|
2
|
+
|
3
|
+
test('Sets.permute', () => {
|
4
|
+
expect(Sets.permute(['a', 'b', 'c'])).toEqual([
|
5
|
+
['a', 'b', 'c'],
|
6
|
+
['a', 'c', 'b'],
|
7
|
+
['b', 'a', 'c'],
|
8
|
+
['b', 'c', 'a'],
|
9
|
+
['c', 'a', 'b'],
|
10
|
+
['c', 'b', 'a'],
|
11
|
+
])
|
12
|
+
})
|
13
|
+
|
14
|
+
test('Sets.properPowerSet', () => {
|
15
|
+
expect(Sets.properPowerSet(['a', 'b', 'c'])).toEqual([['a'], ['b'], ['a', 'b'], ['c'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']])
|
16
|
+
})
|
17
|
+
|
18
|
+
test('Sets.powerSet', () => {
|
19
|
+
expect(Sets.powerSet(['a', 'b', 'c'])).toEqual([[], ['a'], ['b'], ['a', 'b'], ['c'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']])
|
20
|
+
})
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Strings } from '@bessemer/cornerstone'
|
2
|
+
|
3
|
+
// JOHN need to get test suite to actually run again
|
4
|
+
test('Strings.splitFirst', () => {
|
5
|
+
expect(Strings.splitFirst('this.is.a.string.', '.')).toEqual({ selection: 'this', separator: '.', rest: 'is.a.string.' })
|
6
|
+
expect(Strings.splitFirst('', '/')).toEqual({ selection: null, separator: null, rest: '' })
|
7
|
+
expect(Strings.splitFirst('thisisastring', '.')).toEqual({ selection: null, separator: null, rest: 'thisisastring' })
|
8
|
+
expect(Strings.splitFirst('this123is123a123string', '123')).toEqual({ selection: 'this', separator: '123', rest: 'is123a123string' })
|
9
|
+
expect(Strings.splitFirst('/test', '/')).toEqual({ selection: '', separator: '/', rest: 'test' })
|
10
|
+
expect(Strings.splitFirst('test/', '/')).toEqual({ selection: 'test', separator: '/', rest: '' })
|
11
|
+
expect(Strings.splitFirst('//test/', '/')).toEqual({ selection: '', separator: '/', rest: '/test/' })
|
12
|
+
})
|
13
|
+
|
14
|
+
test('Strings.splitLast', () => {
|
15
|
+
expect(Strings.splitLast('.this.is.a.string', '.')).toEqual({ selection: 'string', separator: '.', rest: '.this.is.a' })
|
16
|
+
expect(Strings.splitLast('', '/')).toEqual({ selection: null, separator: null, rest: '' })
|
17
|
+
expect(Strings.splitLast('thisisastring', '.')).toEqual({ selection: null, separator: null, rest: 'thisisastring' })
|
18
|
+
expect(Strings.splitLast('this123is123a123string', '123')).toEqual({ selection: 'string', separator: '123', rest: 'this123is123a' })
|
19
|
+
expect(Strings.splitLast('/test', '/')).toEqual({ selection: 'test', separator: '/', rest: '' })
|
20
|
+
expect(Strings.splitLast('test/', '/')).toEqual({ selection: '', separator: '/', rest: 'test' })
|
21
|
+
expect(Strings.splitLast('//test/', '/')).toEqual({ selection: '', separator: '/', rest: '//test' })
|
22
|
+
})
|
package/test/uri.test.ts
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
import { Uris } from '@bessemer/cornerstone'
|
2
|
+
|
3
|
+
test('Uris.parse / Uris.build', () => {
|
4
|
+
expect(Uris.parse('tel:+1-816-555-1212')).toEqual(
|
5
|
+
Uris.build({
|
6
|
+
scheme: 'tel',
|
7
|
+
location: {
|
8
|
+
path: '+1-816-555-1212',
|
9
|
+
},
|
10
|
+
})
|
11
|
+
)
|
12
|
+
|
13
|
+
expect(Uris.parse('tel:+1-816-555-1212?#')).toEqual(
|
14
|
+
Uris.build({
|
15
|
+
scheme: 'tel',
|
16
|
+
location: '+1-816-555-1212',
|
17
|
+
})
|
18
|
+
)
|
19
|
+
|
20
|
+
expect(Uris.parse('tel:+1-816-555-1212?#fragment')).toEqual(
|
21
|
+
Uris.build({
|
22
|
+
scheme: 'tel',
|
23
|
+
location: {
|
24
|
+
path: '+1-816-555-1212',
|
25
|
+
fragment: 'fragment',
|
26
|
+
},
|
27
|
+
})
|
28
|
+
)
|
29
|
+
|
30
|
+
expect(Uris.parse('telnet://192.0.2.16:80/')).toEqual(
|
31
|
+
Uris.build({
|
32
|
+
scheme: 'telnet',
|
33
|
+
host: {
|
34
|
+
value: '192.0.2.16',
|
35
|
+
port: 80,
|
36
|
+
},
|
37
|
+
location: {
|
38
|
+
path: '/',
|
39
|
+
},
|
40
|
+
})
|
41
|
+
)
|
42
|
+
|
43
|
+
expect(Uris.parse('telnet://192.0.2.16:80')).toEqual(
|
44
|
+
Uris.build({
|
45
|
+
scheme: 'telnet',
|
46
|
+
host: '192.0.2.16:80',
|
47
|
+
location: '',
|
48
|
+
})
|
49
|
+
)
|
50
|
+
|
51
|
+
expect(Uris.parse('urn:oasis:names:specification:docbook:dtd:xml:4.1.2')).toEqual(
|
52
|
+
Uris.build({
|
53
|
+
scheme: 'urn',
|
54
|
+
location: 'oasis:names:specification:docbook:dtd:xml:4.1.2',
|
55
|
+
})
|
56
|
+
)
|
57
|
+
|
58
|
+
expect(Uris.parse('news:comp.infosystems.www.servers.unix')).toEqual(
|
59
|
+
Uris.build({
|
60
|
+
scheme: 'news',
|
61
|
+
location: {
|
62
|
+
path: 'comp.infosystems.www.servers.unix',
|
63
|
+
},
|
64
|
+
})
|
65
|
+
)
|
66
|
+
|
67
|
+
expect(Uris.parse('ldap://[2001:db8::7]/c=GB?objectClass?one')).toEqual(
|
68
|
+
Uris.build({
|
69
|
+
scheme: 'ldap',
|
70
|
+
host: {
|
71
|
+
value: '[2001:db8::7]',
|
72
|
+
},
|
73
|
+
location: {
|
74
|
+
path: '/c=GB',
|
75
|
+
query: 'objectClass?one',
|
76
|
+
},
|
77
|
+
})
|
78
|
+
)
|
79
|
+
|
80
|
+
expect(Uris.parse('ldap://[2001:db8::7]:389/c=GB?objectClass?one')).toEqual(
|
81
|
+
Uris.build({
|
82
|
+
scheme: 'ldap',
|
83
|
+
host: {
|
84
|
+
value: '[2001:db8::7]',
|
85
|
+
port: 389,
|
86
|
+
},
|
87
|
+
location: {
|
88
|
+
path: '/c=GB',
|
89
|
+
query: 'objectClass?one',
|
90
|
+
},
|
91
|
+
})
|
92
|
+
)
|
93
|
+
|
94
|
+
expect(Uris.parse('https://john.doe@www.example.com:1234/forum/questions/?tag=networking&order=newest#:~:text=whatever')).toEqual(
|
95
|
+
Uris.build({
|
96
|
+
scheme: 'https',
|
97
|
+
authentication: {
|
98
|
+
principal: 'john.doe',
|
99
|
+
},
|
100
|
+
host: {
|
101
|
+
value: 'www.example.com',
|
102
|
+
port: 1234,
|
103
|
+
},
|
104
|
+
location: {
|
105
|
+
path: '/forum/questions/',
|
106
|
+
query: 'tag=networking&order=newest',
|
107
|
+
fragment: ':~:text=whatever',
|
108
|
+
},
|
109
|
+
})
|
110
|
+
)
|
111
|
+
})
|
package/test/url.test.ts
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
import { Urls } from '@bessemer/cornerstone'
|
2
|
+
|
3
|
+
test('Urls.parse / Urls.build', () => {
|
4
|
+
{
|
5
|
+
expect(Urls.parse('https://www.google.com')).toEqual(
|
6
|
+
Urls.build({
|
7
|
+
scheme: 'https',
|
8
|
+
host: 'www.google.com',
|
9
|
+
})
|
10
|
+
)
|
11
|
+
}
|
12
|
+
{
|
13
|
+
expect(Urls.parse('https://www.google.com/')).toEqual(
|
14
|
+
Urls.build({
|
15
|
+
scheme: 'https',
|
16
|
+
host: 'www.google.com',
|
17
|
+
})
|
18
|
+
)
|
19
|
+
}
|
20
|
+
|
21
|
+
// TODO i think we should try and support these URLs without having to have the double slash
|
22
|
+
{
|
23
|
+
expect(Urls.parse('//www.google.com')).toEqual(
|
24
|
+
Urls.build({
|
25
|
+
host: 'www.google.com',
|
26
|
+
})
|
27
|
+
)
|
28
|
+
}
|
29
|
+
|
30
|
+
{
|
31
|
+
expect(Urls.parse('//www.google.com/')).toEqual(
|
32
|
+
Urls.build({
|
33
|
+
host: 'www.google.com',
|
34
|
+
})
|
35
|
+
)
|
36
|
+
}
|
37
|
+
|
38
|
+
{
|
39
|
+
expect(Urls.parse('http://localhost:8080')).toEqual(
|
40
|
+
Urls.build({
|
41
|
+
scheme: 'http',
|
42
|
+
host: {
|
43
|
+
value: 'localhost',
|
44
|
+
port: 8080,
|
45
|
+
},
|
46
|
+
})
|
47
|
+
)
|
48
|
+
}
|
49
|
+
|
50
|
+
{
|
51
|
+
expect(Urls.parse('http://localhost:8080/')).toEqual(
|
52
|
+
Urls.build({
|
53
|
+
scheme: 'http',
|
54
|
+
host: 'localhost:8080',
|
55
|
+
})
|
56
|
+
)
|
57
|
+
}
|
58
|
+
{
|
59
|
+
expect(Urls.parse('//localhost:8080')).toEqual(
|
60
|
+
Urls.build({
|
61
|
+
host: {
|
62
|
+
value: 'localhost',
|
63
|
+
port: 8080,
|
64
|
+
},
|
65
|
+
})
|
66
|
+
)
|
67
|
+
}
|
68
|
+
{
|
69
|
+
expect(Urls.parse('//localhost:8080/')).toEqual(
|
70
|
+
Urls.build({
|
71
|
+
host: {
|
72
|
+
value: 'localhost',
|
73
|
+
port: 8080,
|
74
|
+
},
|
75
|
+
})
|
76
|
+
)
|
77
|
+
}
|
78
|
+
|
79
|
+
{
|
80
|
+
expect(Urls.parse('https://john.lutteringer:password123@www.google.com')).toEqual(
|
81
|
+
Urls.build({
|
82
|
+
scheme: 'https',
|
83
|
+
host: 'www.google.com',
|
84
|
+
authentication: {
|
85
|
+
principal: 'john.lutteringer',
|
86
|
+
password: 'password123',
|
87
|
+
},
|
88
|
+
})
|
89
|
+
)
|
90
|
+
}
|
91
|
+
|
92
|
+
{
|
93
|
+
expect(Urls.parse('https://john.lutteringer:password123@www.google.com/')).toEqual(
|
94
|
+
Urls.build({
|
95
|
+
scheme: 'https',
|
96
|
+
host: 'www.google.com',
|
97
|
+
authentication: 'john.lutteringer:password123',
|
98
|
+
})
|
99
|
+
)
|
100
|
+
}
|
101
|
+
|
102
|
+
{
|
103
|
+
expect(Urls.parse('https://john.lutteringer@www.google.com/')).toEqual(
|
104
|
+
Urls.build({
|
105
|
+
scheme: 'https',
|
106
|
+
host: 'www.google.com',
|
107
|
+
authentication: 'john.lutteringer',
|
108
|
+
})
|
109
|
+
)
|
110
|
+
}
|
111
|
+
|
112
|
+
{
|
113
|
+
expect(Urls.parse('john.lutteringer@www.google.com')).toEqual(
|
114
|
+
Urls.build({
|
115
|
+
host: 'www.google.com',
|
116
|
+
authentication: {
|
117
|
+
principal: 'john.lutteringer',
|
118
|
+
},
|
119
|
+
})
|
120
|
+
)
|
121
|
+
}
|
122
|
+
|
123
|
+
{
|
124
|
+
expect(Urls.parse('//john.lutteringer:password123@www.google.com')).toEqual(
|
125
|
+
Urls.build({
|
126
|
+
host: 'www.google.com',
|
127
|
+
authentication: {
|
128
|
+
principal: 'john.lutteringer',
|
129
|
+
password: 'password123',
|
130
|
+
},
|
131
|
+
})
|
132
|
+
)
|
133
|
+
}
|
134
|
+
|
135
|
+
{
|
136
|
+
expect(Urls.parse('//www.google.com?q=Search%20Query')).toEqual(
|
137
|
+
Urls.build({
|
138
|
+
host: 'www.google.com',
|
139
|
+
location: {
|
140
|
+
path: '',
|
141
|
+
parameters: {
|
142
|
+
q: 'Search Query',
|
143
|
+
},
|
144
|
+
},
|
145
|
+
})
|
146
|
+
)
|
147
|
+
}
|
148
|
+
|
149
|
+
{
|
150
|
+
expect(Urls.parse('/search?q=Search%20Query')).toEqual(
|
151
|
+
Urls.build({
|
152
|
+
location: {
|
153
|
+
path: '/search',
|
154
|
+
parameters: {
|
155
|
+
q: 'Search Query',
|
156
|
+
},
|
157
|
+
},
|
158
|
+
})
|
159
|
+
)
|
160
|
+
}
|
161
|
+
|
162
|
+
{
|
163
|
+
expect(Urls.parse('search?q=Search%20Query')).toEqual(
|
164
|
+
Urls.build({
|
165
|
+
location: {
|
166
|
+
path: 'search',
|
167
|
+
parameters: {
|
168
|
+
q: 'Search Query',
|
169
|
+
},
|
170
|
+
},
|
171
|
+
})
|
172
|
+
)
|
173
|
+
}
|
174
|
+
})
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"extends": "../../tsconfig.lib.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "dist",
|
5
|
+
"rootDir": "src",
|
6
|
+
"baseUrl": ".",
|
7
|
+
"paths": {
|
8
|
+
"@bessemer/cornerstone": ["src"],
|
9
|
+
"@bessemer/cornerstone/*": ["src/*"]
|
10
|
+
}
|
11
|
+
},
|
12
|
+
"exclude": ["dist", "node_modules", "test" ,"tsup.config.ts", "jest.config.js"]
|
13
|
+
}
|
package/tsup.config.ts
ADDED