liusuyi
2023-04-24 4737f1e038743ced243c9e52423404d9034d6107
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
'use strict';
 
const Net = require('net');
 
const Address = require('@hapi/address');
const Hoek = require('@hapi/hoek');
 
const Any = require('../any');
const Ref = require('../../ref');
const JoiDate = require('../date');
 
const Uri = require('./uri');
const Ip = require('./ip');
 
 
const internals = {
    uriRegex: Uri.createUriRegex(),
    ipRegex: Ip.createIpRegex(['ipv4', 'ipv6', 'ipvfuture'], 'optional'),
    guidBrackets: {
        '{': '}', '[': ']', '(': ')', '': ''
    },
    guidVersions: {
        uuidv1: '1',
        uuidv2: '2',
        uuidv3: '3',
        uuidv4: '4',
        uuidv5: '5'
    },
    cidrPresences: ['required', 'optional', 'forbidden'],
    normalizationForms: ['NFC', 'NFD', 'NFKC', 'NFKD']
};
 
 
internals.String = class extends Any {
 
    constructor() {
 
        super();
        this._type = 'string';
        this._invalids.add('');
    }
 
    _base(value, state, options) {
 
        if (typeof value === 'string' &&
            options.convert) {
 
            if (this._flags.normalize) {
                value = value.normalize(this._flags.normalize);
            }
 
            if (this._flags.case) {
                value = (this._flags.case === 'upper' ? value.toLocaleUpperCase() : value.toLocaleLowerCase());
            }
 
            if (this._flags.trim) {
                value = value.trim();
            }
 
            if (this._inner.replacements) {
 
                for (let i = 0; i < this._inner.replacements.length; ++i) {
                    const replacement = this._inner.replacements[i];
                    value = value.replace(replacement.pattern, replacement.replacement);
                }
            }
 
            if (this._flags.truncate) {
                for (let i = 0; i < this._tests.length; ++i) {
                    const test = this._tests[i];
                    if (test.name === 'max') {
                        value = value.slice(0, test.arg);
                        break;
                    }
                }
            }
 
            if (this._flags.byteAligned && value.length % 2 !== 0) {
                value = `0${value}`;
            }
        }
 
        return {
            value,
            errors: (typeof value === 'string') ? null : this.createError('string.base', { value }, state, options)
        };
    }
 
    insensitive() {
 
        if (this._flags.insensitive) {
            return this;
        }
 
        const obj = this.clone();
        obj._flags.insensitive = true;
        return obj;
    }
 
    creditCard() {
 
        return this._test('creditCard', undefined, function (value, state, options) {
 
            let i = value.length;
            let sum = 0;
            let mul = 1;
 
            while (i--) {
                const char = value.charAt(i) * mul;
                sum = sum + (char - (char > 9) * 9);
                mul = mul ^ 3;
            }
 
            const check = (sum % 10 === 0) && (sum > 0);
            return check ? value : this.createError('string.creditCard', { value }, state, options);
        });
    }
 
    regex(pattern, patternOptions) {
 
        Hoek.assert(pattern instanceof RegExp, 'pattern must be a RegExp');
        Hoek.assert(!pattern.flags.includes('g') && !pattern.flags.includes('y'), 'pattern should not use global or sticky mode');
 
        const patternObject = { pattern };
 
        if (typeof patternOptions === 'string') {
            patternObject.name = patternOptions;
        }
        else if (typeof patternOptions === 'object') {
            patternObject.invert = !!patternOptions.invert;
 
            if (patternOptions.name) {
                patternObject.name = patternOptions.name;
            }
        }
 
        const errorCode = ['string.regex', patternObject.invert ? '.invert' : '', patternObject.name ? '.name' : '.base'].join('');
 
        return this._test('regex', patternObject, function (value, state, options) {
 
            const patternMatch = patternObject.pattern.test(value);
 
            if (patternMatch ^ patternObject.invert) {
                return value;
            }
 
            return this.createError(errorCode, { name: patternObject.name, pattern: patternObject.pattern, value }, state, options);
        });
    }
 
    alphanum() {
 
        return this._test('alphanum', undefined, function (value, state, options) {
 
            if (/^[a-zA-Z0-9]+$/.test(value)) {
                return value;
            }
 
            return this.createError('string.alphanum', { value }, state, options);
        });
    }
 
    token() {
 
        return this._test('token', undefined, function (value, state, options) {
 
            if (/^\w+$/.test(value)) {
                return value;
            }
 
            return this.createError('string.token', { value }, state, options);
        });
    }
 
    email(validationOptions) {
 
        if (validationOptions) {
            Hoek.assert(typeof validationOptions === 'object', 'email options must be an object');
 
            // Migration validation for unsupported options
 
            Hoek.assert(validationOptions.checkDNS === undefined, 'checkDNS option is not supported');
            Hoek.assert(validationOptions.errorLevel === undefined, 'errorLevel option is not supported');
            Hoek.assert(validationOptions.minDomainAtoms === undefined, 'minDomainAtoms option is not supported, use minDomainSegments instead');
            Hoek.assert(validationOptions.tldBlacklist === undefined, 'tldBlacklist option is not supported, use tlds.deny instead');
            Hoek.assert(validationOptions.tldWhitelist === undefined, 'tldWhitelist option is not supported, use tlds.allow instead');
 
            // Validate options
 
            if (validationOptions.tlds &&
                typeof validationOptions.tlds === 'object') {
 
                Hoek.assert(validationOptions.tlds.allow === undefined ||
                    validationOptions.tlds.allow === false ||
                    validationOptions.tlds.allow === true ||
                    Array.isArray(validationOptions.tlds.allow) ||
                    validationOptions.tlds.allow instanceof Set, 'tlds.allow must be an array, Set, or boolean');
 
                Hoek.assert(validationOptions.tlds.deny === undefined ||
                    Array.isArray(validationOptions.tlds.deny) ||
                    validationOptions.tlds.deny instanceof Set, 'tlds.deny must be an array or Set');
 
                const normalizeTable = (table) => {
 
                    if (table === undefined ||
                        typeof table === 'boolean' ||
                        table instanceof Set) {
 
                        return table;
                    }
 
                    return new Set(table);
                };
 
                validationOptions = Object.assign({}, validationOptions);       // Shallow cloned
                validationOptions.tlds = {
                    allow: normalizeTable(validationOptions.tlds.allow),
                    deny: normalizeTable(validationOptions.tlds.deny)
                };
            }
 
            Hoek.assert(validationOptions.minDomainSegments === undefined ||
                Number.isSafeInteger(validationOptions.minDomainSegments) && validationOptions.minDomainSegments > 0, 'minDomainSegments must be a positive integer');
        }
 
        return this._test('email', validationOptions, function (value, state, options) {
 
            if (Address.email.isValid(value, validationOptions)) {
                return value;
            }
 
            return this.createError('string.email', { value }, state, options);
        });
    }
 
    ip(ipOptions = {}) {
 
        let regex = internals.ipRegex;
        Hoek.assert(typeof ipOptions === 'object', 'options must be an object');
 
        if (ipOptions.cidr) {
            Hoek.assert(typeof ipOptions.cidr === 'string', 'cidr must be a string');
            ipOptions.cidr = ipOptions.cidr.toLowerCase();
 
            Hoek.assert(Hoek.contain(internals.cidrPresences, ipOptions.cidr), 'cidr must be one of ' + internals.cidrPresences.join(', '));
 
            // If we only received a `cidr` setting, create a regex for it. But we don't need to create one if `cidr` is "optional" since that is the default
            if (!ipOptions.version && ipOptions.cidr !== 'optional') {
                regex = Ip.createIpRegex(['ipv4', 'ipv6', 'ipvfuture'], ipOptions.cidr);
            }
        }
        else {
 
            // Set our default cidr strategy
            ipOptions.cidr = 'optional';
        }
 
        let versions;
        if (ipOptions.version) {
            if (!Array.isArray(ipOptions.version)) {
                ipOptions.version = [ipOptions.version];
            }
 
            Hoek.assert(ipOptions.version.length >= 1, 'version must have at least 1 version specified');
 
            versions = [];
            for (let i = 0; i < ipOptions.version.length; ++i) {
                let version = ipOptions.version[i];
                Hoek.assert(typeof version === 'string', 'version at position ' + i + ' must be a string');
                version = version.toLowerCase();
                Hoek.assert(Ip.versions[version], 'version at position ' + i + ' must be one of ' + Object.keys(Ip.versions).join(', '));
                versions.push(version);
            }
 
            // Make sure we have a set of versions
            versions = Array.from(new Set(versions));
 
            regex = Ip.createIpRegex(versions, ipOptions.cidr);
        }
 
        return this._test('ip', ipOptions, function (value, state, options) {
 
            if (regex.test(value)) {
                return value;
            }
 
            if (versions) {
                return this.createError('string.ipVersion', { value, cidr: ipOptions.cidr, version: versions }, state, options);
            }
 
            return this.createError('string.ip', { value, cidr: ipOptions.cidr }, state, options);
        });
    }
 
    uri(uriOptions) {
 
        let customScheme = '';
        let allowRelative = false;
        let relativeOnly = false;
        let allowQuerySquareBrackets = false;
        let regex = internals.uriRegex;
 
        if (uriOptions) {
            Hoek.assert(typeof uriOptions === 'object', 'options must be an object');
 
            const unknownOptions = Object.keys(uriOptions).filter((key) => !['scheme', 'allowRelative', 'relativeOnly', 'allowQuerySquareBrackets'].includes(key));
            Hoek.assert(unknownOptions.length === 0, `options contain unknown keys: ${unknownOptions}`);
 
            if (uriOptions.scheme) {
                Hoek.assert(uriOptions.scheme instanceof RegExp || typeof uriOptions.scheme === 'string' || Array.isArray(uriOptions.scheme), 'scheme must be a RegExp, String, or Array');
 
                if (!Array.isArray(uriOptions.scheme)) {
                    uriOptions.scheme = [uriOptions.scheme];
                }
 
                Hoek.assert(uriOptions.scheme.length >= 1, 'scheme must have at least 1 scheme specified');
 
                // Flatten the array into a string to be used to match the schemes.
                for (let i = 0; i < uriOptions.scheme.length; ++i) {
                    const scheme = uriOptions.scheme[i];
                    Hoek.assert(scheme instanceof RegExp || typeof scheme === 'string', 'scheme at position ' + i + ' must be a RegExp or String');
 
                    // Add OR separators if a value already exists
                    customScheme = customScheme + (customScheme ? '|' : '');
 
                    // If someone wants to match HTTP or HTTPS for example then we need to support both RegExp and String so we don't escape their pattern unknowingly.
                    if (scheme instanceof RegExp) {
                        customScheme = customScheme + scheme.source;
                    }
                    else {
                        Hoek.assert(/[a-zA-Z][a-zA-Z0-9+-\.]*/.test(scheme), 'scheme at position ' + i + ' must be a valid scheme');
                        customScheme = customScheme + Hoek.escapeRegex(scheme);
                    }
                }
            }
 
            if (uriOptions.allowRelative) {
                allowRelative = true;
            }
 
            if (uriOptions.relativeOnly) {
                relativeOnly = true;
            }
 
            if (uriOptions.allowQuerySquareBrackets) {
                allowQuerySquareBrackets = true;
            }
        }
 
        if (customScheme || allowRelative || relativeOnly || allowQuerySquareBrackets) {
            regex = Uri.createUriRegex(customScheme, allowRelative, relativeOnly, allowQuerySquareBrackets);
        }
 
        return this._test('uri', uriOptions, function (value, state, options) {
 
            if (regex.test(value)) {
                return value;
            }
 
            if (relativeOnly) {
                return this.createError('string.uriRelativeOnly', { value }, state, options);
            }
 
            if (customScheme) {
                return this.createError('string.uriCustomScheme', { scheme: customScheme, value }, state, options);
            }
 
            return this.createError('string.uri', { value }, state, options);
        });
    }
 
    isoDate() {
 
        return this._test('isoDate', undefined, function (value, state, options) {
 
            if (JoiDate._isIsoDate(value)) {
                if (!options.convert) {
                    return value;
                }
 
                const d = new Date(value);
                if (!isNaN(d.getTime())) {
                    return d.toISOString();
                }
            }
 
            return this.createError('string.isoDate', { value }, state, options);
        });
    }
 
    guid(guidOptions) {
 
        let versionNumbers = '';
 
        if (guidOptions && guidOptions.version) {
            if (!Array.isArray(guidOptions.version)) {
                guidOptions.version = [guidOptions.version];
            }
 
            Hoek.assert(guidOptions.version.length >= 1, 'version must have at least 1 valid version specified');
            const versions = new Set();
 
            for (let i = 0; i < guidOptions.version.length; ++i) {
                let version = guidOptions.version[i];
                Hoek.assert(typeof version === 'string', 'version at position ' + i + ' must be a string');
                version = version.toLowerCase();
                const versionNumber = internals.guidVersions[version];
                Hoek.assert(versionNumber, 'version at position ' + i + ' must be one of ' + Object.keys(internals.guidVersions).join(', '));
                Hoek.assert(!(versions.has(versionNumber)), 'version at position ' + i + ' must not be a duplicate.');
 
                versionNumbers += versionNumber;
                versions.add(versionNumber);
            }
        }
 
        const guidRegex = new RegExp(`^([\\[{\\(]?)[0-9A-F]{8}([:-]?)[0-9A-F]{4}\\2?[${versionNumbers || '0-9A-F'}][0-9A-F]{3}\\2?[${versionNumbers ? '89AB' : '0-9A-F'}][0-9A-F]{3}\\2?[0-9A-F]{12}([\\]}\\)]?)$`, 'i');
 
        return this._test('guid', guidOptions, function (value, state, options) {
 
            const results = guidRegex.exec(value);
 
            if (!results) {
                return this.createError('string.guid', { value }, state, options);
            }
 
            // Matching braces
            if (internals.guidBrackets[results[1]] !== results[results.length - 1]) {
                return this.createError('string.guid', { value }, state, options);
            }
 
            return value;
        });
    }
 
    hex(hexOptions = {}) {
 
        Hoek.assert(typeof hexOptions === 'object', 'hex options must be an object');
        Hoek.assert(typeof hexOptions.byteAligned === 'undefined' || typeof hexOptions.byteAligned === 'boolean',
            'byteAligned must be boolean');
 
        const byteAligned = hexOptions.byteAligned === true;
        const regex = /^[a-f0-9]+$/i;
 
        const obj = this._test('hex', regex, function (value, state, options) {
 
            if (regex.test(value)) {
                if (byteAligned && value.length % 2 !== 0) {
                    return this.createError('string.hexAlign', { value }, state, options);
                }
 
                return value;
            }
 
            return this.createError('string.hex', { value }, state, options);
        });
 
        if (byteAligned) {
            obj._flags.byteAligned = true;
        }
 
        return obj;
    }
 
    base64(base64Options = {}) {
 
        // Validation.
        Hoek.assert(typeof base64Options === 'object', 'base64 options must be an object');
        Hoek.assert(typeof base64Options.paddingRequired === 'undefined' || typeof base64Options.paddingRequired === 'boolean',
            'paddingRequired must be boolean');
 
        // Determine if padding is required.
        const paddingRequired = base64Options.paddingRequired === false ?
            base64Options.paddingRequired
            : base64Options.paddingRequired || true;
 
        // Set validation based on preference.
        const regex = paddingRequired ?
            // Padding is required.
            /^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/
            // Padding is optional.
            : /^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}(==)?|[A-Za-z0-9+\/]{3}=?)?$/;
 
        return this._test('base64', regex, function (value, state, options) {
 
            if (regex.test(value)) {
                return value;
            }
 
            return this.createError('string.base64', { value }, state, options);
        });
    }
 
    dataUri(dataUriOptions = {}) {
 
        const regex = /^data:[\w+.-]+\/[\w+.-]+;((charset=[\w-]+|base64),)?(.*)$/;
 
        // Determine if padding is required.
        const paddingRequired = dataUriOptions.paddingRequired === false ?
            dataUriOptions.paddingRequired
            : dataUriOptions.paddingRequired || true;
 
        const base64regex = paddingRequired ?
            /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/
            : /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}(==)?|[A-Za-z0-9+\/]{3}=?)?$/;
 
        return this._test('dataUri', regex, function (value, state, options) {
 
            const matches = value.match(regex);
 
            if (matches) {
                if (!matches[2]) {
                    return value;
                }
 
                if (matches[2] !== 'base64') {
                    return value;
                }
 
                if (base64regex.test(matches[3])) {
                    return value;
                }
            }
 
            return this.createError('string.dataUri', { value }, state, options);
        });
    }
 
    hostname() {
 
        const regex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
 
        return this._test('hostname', undefined, function (value, state, options) {
 
            if ((value.length <= 255 && regex.test(value)) ||
                Net.isIPv6(value)) {
 
                return value;
            }
 
            return this.createError('string.hostname', { value }, state, options);
        });
    }
 
    normalize(form = 'NFC') {
 
        Hoek.assert(Hoek.contain(internals.normalizationForms, form), 'normalization form must be one of ' + internals.normalizationForms.join(', '));
 
        const obj = this._test('normalize', form, function (value, state, options) {
 
            if (options.convert ||
                value === value.normalize(form)) {
 
                return value;
            }
 
            return this.createError('string.normalize', { value, form }, state, options);
        });
 
        obj._flags.normalize = form;
        return obj;
    }
 
    lowercase() {
 
        const obj = this._test('lowercase', undefined, function (value, state, options) {
 
            if (options.convert ||
                value === value.toLocaleLowerCase()) {
 
                return value;
            }
 
            return this.createError('string.lowercase', { value }, state, options);
        });
 
        obj._flags.case = 'lower';
        return obj;
    }
 
    uppercase() {
 
        const obj = this._test('uppercase', undefined, function (value, state, options) {
 
            if (options.convert ||
                value === value.toLocaleUpperCase()) {
 
                return value;
            }
 
            return this.createError('string.uppercase', { value }, state, options);
        });
 
        obj._flags.case = 'upper';
        return obj;
    }
 
    trim(enabled = true) {
 
        Hoek.assert(typeof enabled === 'boolean', 'option must be a boolean');
 
        if ((this._flags.trim && enabled) || (!this._flags.trim && !enabled)) {
            return this;
        }
 
        let obj;
        if (enabled) {
            obj = this._test('trim', undefined, function (value, state, options) {
 
                if (options.convert ||
                    value === value.trim()) {
 
                    return value;
                }
 
                return this.createError('string.trim', { value }, state, options);
            });
        }
        else {
            obj = this.clone();
            obj._tests = obj._tests.filter((test) => test.name !== 'trim');
        }
 
        obj._flags.trim = enabled;
        return obj;
    }
 
    replace(pattern, replacement) {
 
        if (typeof pattern === 'string') {
            pattern = new RegExp(Hoek.escapeRegex(pattern), 'g');
        }
 
        Hoek.assert(pattern instanceof RegExp, 'pattern must be a RegExp');
        Hoek.assert(typeof replacement === 'string', 'replacement must be a String');
 
        // This can not be considere a test like trim, we can't "reject"
        // anything from this rule, so just clone the current object
        const obj = this.clone();
 
        if (!obj._inner.replacements) {
            obj._inner.replacements = [];
        }
 
        obj._inner.replacements.push({
            pattern,
            replacement
        });
 
        return obj;
    }
 
    truncate(enabled) {
 
        const value = enabled === undefined ? true : !!enabled;
 
        if (this._flags.truncate === value) {
            return this;
        }
 
        const obj = this.clone();
        obj._flags.truncate = value;
        return obj;
    }
 
};
 
internals.compare = function (type, compare) {
 
    return function (limit, encoding) {
 
        const isRef = Ref.isRef(limit);
 
        Hoek.assert((Number.isSafeInteger(limit) && limit >= 0) || isRef, 'limit must be a positive integer or reference');
        Hoek.assert(!encoding || Buffer.isEncoding(encoding), 'Invalid encoding:', encoding);
 
        return this._test(type, limit, function (value, state, options) {
 
            let compareTo;
            if (isRef) {
                compareTo = limit(state.reference || state.parent, options);
 
                if (!Number.isSafeInteger(compareTo)) {
                    return this.createError('string.ref', { ref: limit, value: compareTo }, state, options);
                }
            }
            else {
                compareTo = limit;
            }
 
            if (compare(value, compareTo, encoding)) {
                return value;
            }
 
            return this.createError('string.' + type, { limit: compareTo, value, encoding }, state, options);
        });
    };
};
 
 
internals.String.prototype.min = internals.compare('min', (value, limit, encoding) => {
 
    const length = encoding ? Buffer.byteLength(value, encoding) : value.length;
    return length >= limit;
});
 
 
internals.String.prototype.max = internals.compare('max', (value, limit, encoding) => {
 
    const length = encoding ? Buffer.byteLength(value, encoding) : value.length;
    return length <= limit;
});
 
 
internals.String.prototype.length = internals.compare('length', (value, limit, encoding) => {
 
    const length = encoding ? Buffer.byteLength(value, encoding) : value.length;
    return length === limit;
});
 
// Aliases
 
internals.String.prototype.uuid = internals.String.prototype.guid;
 
module.exports = new internals.String();