asma-core-helpers 0.31.0 → 0.32.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/lib/validation/index.d.ts +1 -1
- package/lib/validation/index.d.ts.map +1 -1
- package/lib/validation/index.js +1 -1
- package/lib/validation/index.js.map +1 -1
- package/lib/validation/rules.d.ts +4 -0
- package/lib/validation/rules.d.ts.map +1 -1
- package/lib/validation/rules.js +18 -1
- package/lib/validation/rules.js.map +1 -1
- package/package.json +1 -1
- package/src/validation/index.ts +15 -1
- package/src/validation/rules.test.ts +106 -1
- package/src/validation/rules.ts +25 -1
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* consumers never pull browser-only helpers that read `window` on import.
|
|
6
6
|
*/
|
|
7
7
|
export { errorWithHint, getValidationMessages, validationMessages, type ValidationLocale, type ValidationMessageKey, type ValidationMessages, } from './messages.js';
|
|
8
|
-
export { email, emailRegex, name, nameRegex, pattern, phoneNr, phoneNrRegex, pnr, required } from './rules.js';
|
|
8
|
+
export { email, emailRegex, hasDigit, httpUrl, name, nameChars, nameCharsRegex, nameRegex, pattern, phoneNr, phoneNrRegex, pnr, required, } from './rules.js';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GAC1B,MAAM,eAAe,CAAA;AAEtB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GAC1B,MAAM,eAAe,CAAA;AAEtB,OAAO,EACH,KAAK,EACL,UAAU,EACV,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,SAAS,EACT,cAAc,EACd,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,GAAG,EACH,QAAQ,GACX,MAAM,YAAY,CAAA"}
|
package/lib/validation/index.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* consumers never pull browser-only helpers that read `window` on import.
|
|
6
6
|
*/
|
|
7
7
|
export { errorWithHint, getValidationMessages, validationMessages, } from './messages.js';
|
|
8
|
-
export { email, emailRegex, name, nameRegex, pattern, phoneNr, phoneNrRegex, pnr, required } from './rules.js';
|
|
8
|
+
export { email, emailRegex, hasDigit, httpUrl, name, nameChars, nameCharsRegex, nameRegex, pattern, phoneNr, phoneNrRegex, pnr, required, } from './rules.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,aAAa,EACb,qBAAqB,EACrB,kBAAkB,GAIrB,MAAM,eAAe,CAAA;AAEtB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,aAAa,EACb,qBAAqB,EACrB,kBAAkB,GAIrB,MAAM,eAAe,CAAA;AAEtB,OAAO,EACH,KAAK,EACL,UAAU,EACV,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,SAAS,EACT,cAAc,EACd,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,GAAG,EACH,QAAQ,GACX,MAAM,YAAY,CAAA"}
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
export declare const phoneNrRegex: RegExp;
|
|
3
3
|
export declare const emailRegex: RegExp;
|
|
4
4
|
export declare const nameRegex: RegExp;
|
|
5
|
+
export declare const nameCharsRegex: RegExp;
|
|
6
|
+
export declare function hasDigit(value: string): boolean;
|
|
7
|
+
export declare function nameChars(value: string): boolean;
|
|
5
8
|
export declare function required(value: unknown): boolean;
|
|
6
9
|
export declare function email(value: string): boolean;
|
|
7
10
|
export declare function name(value: string): boolean;
|
|
8
11
|
export declare function phoneNr(value: string): boolean;
|
|
9
12
|
export declare function pattern(value: string, regex: RegExp): boolean;
|
|
10
13
|
export declare function pnr(value: string): boolean;
|
|
14
|
+
export declare function httpUrl(value: string): boolean;
|
|
11
15
|
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/validation/rules.ts"],"names":[],"mappings":"AAEA,qHAAqH;AACrH,eAAO,MAAM,YAAY,QAAkB,CAAA;AAC3C,eAAO,MAAM,UAAU,QAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/validation/rules.ts"],"names":[],"mappings":"AAEA,qHAAqH;AACrH,eAAO,MAAM,YAAY,QAAkB,CAAA;AAC3C,eAAO,MAAM,UAAU,QAAoC,CAAA;AAG3D,eAAO,MAAM,SAAS,QAGrB,CAAA;AAED,eAAO,MAAM,cAAc,QAAuD,CAAA;AAElF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIhD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO9C"}
|
package/lib/validation/rules.js
CHANGED
|
@@ -2,7 +2,15 @@ import { getValidNorwegianPersonalNumber } from '../helpers/validateNorwegianPer
|
|
|
2
2
|
/** Copied from directory/asma-app-directory ActorToUpsertValidator regex helpers — keep pilot behavior identical. */
|
|
3
3
|
export const phoneNrRegex = /^\+?\d{6,13}$/;
|
|
4
4
|
export const emailRegex = /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/;
|
|
5
|
-
|
|
5
|
+
const NAME_PUNCTUATION = ".,'\u2019\u2013\u2014-";
|
|
6
|
+
export const nameRegex = new RegExp(`^\\s*\\p{Lu}[\\p{L}${NAME_PUNCTUATION}]*(\\s+\\p{L}[\\p{L}${NAME_PUNCTUATION}]*)*\\s*$`, 'u');
|
|
7
|
+
export const nameCharsRegex = new RegExp(`^[\\p{L}\\s${NAME_PUNCTUATION}]*$`, 'u');
|
|
8
|
+
export function hasDigit(value) {
|
|
9
|
+
return /\d/.test(value);
|
|
10
|
+
}
|
|
11
|
+
export function nameChars(value) {
|
|
12
|
+
return nameCharsRegex.test(value);
|
|
13
|
+
}
|
|
6
14
|
export function required(value) {
|
|
7
15
|
if (value == null)
|
|
8
16
|
return false;
|
|
@@ -25,4 +33,13 @@ export function pattern(value, regex) {
|
|
|
25
33
|
export function pnr(value) {
|
|
26
34
|
return getValidNorwegianPersonalNumber(value) != null;
|
|
27
35
|
}
|
|
36
|
+
export function httpUrl(value) {
|
|
37
|
+
try {
|
|
38
|
+
const { protocol } = new URL(value.trim());
|
|
39
|
+
return protocol === 'http:' || protocol === 'https:';
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
28
45
|
//# sourceMappingURL=rules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/validation/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAA;AAE/F,qHAAqH;AACrH,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAA;AAC3C,MAAM,CAAC,MAAM,UAAU,GAAG,iCAAiC,CAAA;AAC3D,MAAM,CAAC,MAAM,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/validation/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAA;AAE/F,qHAAqH;AACrH,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAA;AAC3C,MAAM,CAAC,MAAM,UAAU,GAAG,iCAAiC,CAAA;AAC3D,MAAM,gBAAgB,GAAG,wBAAwB,CAAA;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,MAAM,CAC/B,sBAAsB,gBAAgB,uBAAuB,gBAAgB,WAAW,EACxF,GAAG,CACN,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,cAAc,gBAAgB,KAAK,EAAE,GAAG,CAAC,CAAA;AAElF,MAAM,UAAU,QAAQ,CAAC,KAAa;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAa;IACnC,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACnC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAA;IAC7D,OAAO,IAAI,CAAA;AACf,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAa;IAC/B,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAa;IAC9B,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa;IACjC,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,KAAa;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAAa;IAC7B,OAAO,+BAA+B,CAAC,KAAK,CAAC,IAAI,IAAI,CAAA;AACzD,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa;IACjC,IAAI,CAAC;QACD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;QAC1C,OAAO,QAAQ,KAAK,OAAO,IAAI,QAAQ,KAAK,QAAQ,CAAA;IACxD,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAA;IAChB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/validation/index.ts
CHANGED
|
@@ -14,4 +14,18 @@ export {
|
|
|
14
14
|
type ValidationMessages,
|
|
15
15
|
} from './messages.js'
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export {
|
|
18
|
+
email,
|
|
19
|
+
emailRegex,
|
|
20
|
+
hasDigit,
|
|
21
|
+
httpUrl,
|
|
22
|
+
name,
|
|
23
|
+
nameChars,
|
|
24
|
+
nameCharsRegex,
|
|
25
|
+
nameRegex,
|
|
26
|
+
pattern,
|
|
27
|
+
phoneNr,
|
|
28
|
+
phoneNrRegex,
|
|
29
|
+
pnr,
|
|
30
|
+
required,
|
|
31
|
+
} from './rules.js'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
import { describe, it } from 'node:test'
|
|
3
3
|
|
|
4
|
-
import { email, name, pattern, phoneNr, pnr, required } from './rules.js'
|
|
4
|
+
import { email, hasDigit, httpUrl, name, nameChars, pattern, phoneNr, pnr, required } from './rules.js'
|
|
5
5
|
|
|
6
6
|
describe('required', () => {
|
|
7
7
|
it('rejects empty, whitespace, null, undefined', () => {
|
|
@@ -38,6 +38,86 @@ describe('name', () => {
|
|
|
38
38
|
assert.equal(name('john'), false)
|
|
39
39
|
assert.equal(name(''), false)
|
|
40
40
|
})
|
|
41
|
+
|
|
42
|
+
it('accepts the real names it has to accept', () => {
|
|
43
|
+
for (const real of [
|
|
44
|
+
'Bo Henki Steinsland-Tønnessen',
|
|
45
|
+
'Bjørn Emil Gloppen Jørgensen',
|
|
46
|
+
'Bjørge Øfstaas',
|
|
47
|
+
'Kenneth Jul-Larsen',
|
|
48
|
+
'Gun Jorunn Haughom Sørheim',
|
|
49
|
+
'Lone Mjørnaren Darum Jr.',
|
|
50
|
+
'Martine Mosengen Sr.',
|
|
51
|
+
'Tommy André Pedersen',
|
|
52
|
+
'Tuva Elisabeth Næs Andersen',
|
|
53
|
+
'Willian Garthner II ',
|
|
54
|
+
'Porsgrunn commune IKT',
|
|
55
|
+
'Bargan, Constantin',
|
|
56
|
+
]) {
|
|
57
|
+
assert.equal(name(real), true, real)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('accepts every dash an editor may have substituted for the typed hyphen', () => {
|
|
62
|
+
assert.equal(name('Anne-Marie Hansen'), true)
|
|
63
|
+
assert.equal(name('Anne\u2013Marie Hansen'), true)
|
|
64
|
+
assert.equal(name('Anne\u2014Marie Hansen'), true)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('accepts both apostrophes — editors substitute the typographic one silently', () => {
|
|
68
|
+
assert.equal(name("O'Brien"), true)
|
|
69
|
+
assert.equal(name('O\u2019Brien'), true)
|
|
70
|
+
assert.equal(name("Lars D'Angelo Næss"), true)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('treats Norwegian letters as ordinary letters', () => {
|
|
74
|
+
assert.equal(name('Æse Ørn Ådne'), true)
|
|
75
|
+
assert.equal(name('Øystein'), true)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('rejects digits anywhere, not just as the first character', () => {
|
|
79
|
+
assert.equal(name('Ivan123'), false)
|
|
80
|
+
assert.equal(name('123'), false)
|
|
81
|
+
assert.equal(name('Ivan 123'), false)
|
|
82
|
+
assert.equal(name('Willian Garthner 2'), false)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('rejects a lower-case opening and punctuation the set does not cover', () => {
|
|
86
|
+
assert.equal(name('kenneth Jul-Larsen'), false)
|
|
87
|
+
assert.equal(name('Foo;Bar'), false)
|
|
88
|
+
assert.equal(name('Foo@Bar'), false)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('nameChars', () => {
|
|
93
|
+
it('accepts every character a name is built from', () => {
|
|
94
|
+
assert.equal(nameChars('Bargan, Constantin'), true)
|
|
95
|
+
assert.equal(nameChars("Lone Mjørnaren Darum Jr. O'Brien"), true)
|
|
96
|
+
assert.equal(nameChars('vasilii'), true) // case is not its business
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('rejects anything else, which is what lets the field name the real problem', () => {
|
|
100
|
+
assert.equal(nameChars('Vasilii&'), false)
|
|
101
|
+
assert.equal(nameChars('Foo;Bar'), false)
|
|
102
|
+
assert.equal(nameChars('Foo@Bar'), false)
|
|
103
|
+
assert.equal(nameChars('Ivan123'), false)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('agrees with nameRegex about every character it allows', () => {
|
|
107
|
+
for (const char of ["-", ".", ",", "'", "\u2019"]) {
|
|
108
|
+
assert.equal(nameChars(`Aa${char}bb`), true, char)
|
|
109
|
+
assert.equal(name(`Aa${char}bb`), true, char)
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe('hasDigit', () => {
|
|
115
|
+
it('separates "there is a number in here" from every other name failure', () => {
|
|
116
|
+
assert.equal(hasDigit('Ivan123'), true)
|
|
117
|
+
assert.equal(hasDigit('123'), true)
|
|
118
|
+
assert.equal(hasDigit('ivan'), false)
|
|
119
|
+
assert.equal(hasDigit('Ann-Kristin'), false)
|
|
120
|
+
})
|
|
41
121
|
})
|
|
42
122
|
|
|
43
123
|
describe('phoneNr', () => {
|
|
@@ -70,3 +150,28 @@ describe('pnr', () => {
|
|
|
70
150
|
assert.equal(pnr('00000000000'), false)
|
|
71
151
|
})
|
|
72
152
|
})
|
|
153
|
+
|
|
154
|
+
describe('httpUrl', () => {
|
|
155
|
+
it('accepts ordinary web addresses', () => {
|
|
156
|
+
assert.equal(httpUrl('https://example.com'), true)
|
|
157
|
+
assert.equal(httpUrl('http://example.com'), true)
|
|
158
|
+
assert.equal(httpUrl('https://dok.adcuris.no/ad-voca/uO5TQY5Z2K271Ycumsj5'), true)
|
|
159
|
+
assert.equal(httpUrl(' https://example.com '), true)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('accepts ports, fragments, internationalised hosts and full path/query syntax', () => {
|
|
163
|
+
assert.equal(httpUrl('https://example.com:8080'), true)
|
|
164
|
+
assert.equal(httpUrl('https://example.com/page#section'), true)
|
|
165
|
+
assert.equal(httpUrl('https://bxrum.no'.replace('x', '\u00e6')), true)
|
|
166
|
+
assert.equal(httpUrl('https://example.com/a+b,c~d'), true)
|
|
167
|
+
assert.equal(httpUrl('https://x.no/a?b=c&d=e'), true)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('rejects non-web schemes and scheme-less input', () => {
|
|
171
|
+
assert.equal(httpUrl('mailto:a@b.c'), false)
|
|
172
|
+
assert.equal(httpUrl('foo:bar'), false)
|
|
173
|
+
assert.equal(httpUrl('javascript:alert(1)'), false)
|
|
174
|
+
assert.equal(httpUrl('example.com'), false)
|
|
175
|
+
assert.equal(httpUrl(''), false)
|
|
176
|
+
})
|
|
177
|
+
})
|
package/src/validation/rules.ts
CHANGED
|
@@ -3,7 +3,22 @@ import { getValidNorwegianPersonalNumber } from '../helpers/validateNorwegianPer
|
|
|
3
3
|
/** Copied from directory/asma-app-directory ActorToUpsertValidator regex helpers — keep pilot behavior identical. */
|
|
4
4
|
export const phoneNrRegex = /^\+?\d{6,13}$/
|
|
5
5
|
export const emailRegex = /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/
|
|
6
|
-
|
|
6
|
+
const NAME_PUNCTUATION = ".,'\u2019\u2013\u2014-"
|
|
7
|
+
|
|
8
|
+
export const nameRegex = new RegExp(
|
|
9
|
+
`^\\s*\\p{Lu}[\\p{L}${NAME_PUNCTUATION}]*(\\s+\\p{L}[\\p{L}${NAME_PUNCTUATION}]*)*\\s*$`,
|
|
10
|
+
'u',
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
export const nameCharsRegex = new RegExp(`^[\\p{L}\\s${NAME_PUNCTUATION}]*$`, 'u')
|
|
14
|
+
|
|
15
|
+
export function hasDigit(value: string): boolean {
|
|
16
|
+
return /\d/.test(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function nameChars(value: string): boolean {
|
|
20
|
+
return nameCharsRegex.test(value)
|
|
21
|
+
}
|
|
7
22
|
|
|
8
23
|
export function required(value: unknown): boolean {
|
|
9
24
|
if (value == null) return false
|
|
@@ -30,3 +45,12 @@ export function pattern(value: string, regex: RegExp): boolean {
|
|
|
30
45
|
export function pnr(value: string): boolean {
|
|
31
46
|
return getValidNorwegianPersonalNumber(value) != null
|
|
32
47
|
}
|
|
48
|
+
|
|
49
|
+
export function httpUrl(value: string): boolean {
|
|
50
|
+
try {
|
|
51
|
+
const { protocol } = new URL(value.trim())
|
|
52
|
+
return protocol === 'http:' || protocol === 'https:'
|
|
53
|
+
} catch {
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
}
|