Skip to content

Commit eee42dc

Browse files
Copilotstreamich
andcommitted
Apply code formatting with yarn format:fix
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
1 parent edb4224 commit eee42dc

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

src/schema/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface StringSchema extends TType<string>, WithValidator {
119119
/**
120120
* String format specification. When set, the string value will be validated
121121
* according to the specified format for maximum performance.
122-
*
122+
*
123123
* - "ascii" - Only ASCII characters (0-127) are allowed
124124
* - "utf8" - Valid UTF-8 encoded strings are allowed
125125
*/
@@ -129,7 +129,7 @@ export interface StringSchema extends TType<string>, WithValidator {
129129
* When set to true, means that the string can contain only ASCII characters.
130130
* This enables a range of optimizations, such as using a faster JSON
131131
* serialization, faster binary serialization.
132-
*
132+
*
133133
* @deprecated Use `format: 'ascii'` instead.
134134
*/
135135
ascii?: boolean;

src/type/classes/StringType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class StringType extends AbstractType<schema.StringSchema> {
9191
ctx.js(/* js */ `if(${r}.length > ${max}) return ${err};`);
9292
}
9393
}
94-
94+
9595
if (format) {
9696
const formatErr = ctx.err(ValidationError.STR, path);
9797
if (format === 'ascii') {
@@ -106,7 +106,7 @@ export class StringType extends AbstractType<schema.StringSchema> {
106106
const validateFn = ctx.codegen.linkDependency(isAscii);
107107
ctx.js(/* js */ `if(!${validateFn}(${r})) return ${asciiErr};`);
108108
}
109-
109+
110110
ctx.emitCustomValidators(this, path, r);
111111
}
112112

src/type/classes/__tests__/StringType.format.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('StringType format validation', () => {
2525
test('works with min/max length', () => {
2626
const type = t.String({format: 'ascii', min: 2, max: 5});
2727
const validator = type.validator('boolean');
28-
28+
2929
expect(validator('ab')).toBe(false); // Valid ASCII, correct length
3030
expect(validator('abcde')).toBe(false); // Valid ASCII, correct length
3131
expect(validator('a')).toBe(true); // Too short
@@ -51,9 +51,9 @@ describe('StringType format validation', () => {
5151
test('rejects strings with unpaired surrogates', () => {
5252
const validator = utf8Type.validator('boolean');
5353
// Create strings with unpaired surrogates
54-
const highSurrogate = String.fromCharCode(0xD800); // High surrogate without low
55-
const lowSurrogate = String.fromCharCode(0xDC00); // Low surrogate without high
56-
54+
const highSurrogate = String.fromCharCode(0xd800); // High surrogate without low
55+
const lowSurrogate = String.fromCharCode(0xdc00); // Low surrogate without high
56+
5757
expect(validator(highSurrogate)).toBe(true); // Unpaired high surrogate
5858
expect(validator(lowSurrogate)).toBe(true); // Orphaned low surrogate
5959
expect(validator('hello' + highSurrogate)).toBe(true); // High surrogate at end
@@ -72,15 +72,15 @@ describe('StringType format validation', () => {
7272
test('ascii: true behaves like format: "ascii"', () => {
7373
const asciiType = t.String({ascii: true});
7474
const validator = asciiType.validator('boolean');
75-
75+
7676
expect(validator('hello')).toBe(false); // Valid ASCII
7777
expect(validator('héllo')).toBe(true); // Non-ASCII
7878
});
7979

8080
test('format takes precedence over ascii boolean', () => {
8181
const type = t.String({format: 'utf8', ascii: true});
8282
const validator = type.validator('boolean');
83-
83+
8484
// Should behave as UTF-8 validation, allowing non-ASCII
8585
expect(validator('héllo')).toBe(false); // Should pass UTF-8 validation
8686
});
@@ -119,4 +119,4 @@ describe('StringType format validation', () => {
119119
expect(jsonSchema.pattern).toBe('^[\\x00-\\x7F]*$');
120120
});
121121
});
122-
});
122+
});

src/util/__tests__/stringFormats.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,42 +42,42 @@ describe('String format validation utilities', () => {
4242
});
4343

4444
test('returns false for unpaired high surrogates', () => {
45-
const highSurrogate = String.fromCharCode(0xD800);
45+
const highSurrogate = String.fromCharCode(0xd800);
4646
expect(isUtf8(highSurrogate)).toBe(false);
4747
expect(isUtf8('hello' + highSurrogate)).toBe(false);
4848
expect(isUtf8(highSurrogate + 'world')).toBe(false);
4949
});
5050

5151
test('returns false for orphaned low surrogates', () => {
52-
const lowSurrogate = String.fromCharCode(0xDC00);
52+
const lowSurrogate = String.fromCharCode(0xdc00);
5353
expect(isUtf8(lowSurrogate)).toBe(false);
5454
expect(isUtf8('hello' + lowSurrogate)).toBe(false);
5555
expect(isUtf8(lowSurrogate + 'world')).toBe(false);
5656
});
5757

5858
test('returns false for high surrogate not followed by low surrogate', () => {
59-
const highSurrogate = String.fromCharCode(0xD800);
60-
const notLowSurrogate = String.fromCharCode(0xE000); // Outside surrogate range
59+
const highSurrogate = String.fromCharCode(0xd800);
60+
const notLowSurrogate = String.fromCharCode(0xe000); // Outside surrogate range
6161
expect(isUtf8(highSurrogate + notLowSurrogate)).toBe(false);
6262
expect(isUtf8(highSurrogate + 'a')).toBe(false);
6363
});
6464

6565
test('returns true for valid surrogate pairs', () => {
6666
// Create a valid surrogate pair manually
67-
const highSurrogate = String.fromCharCode(0xD800);
68-
const lowSurrogate = String.fromCharCode(0xDC00);
67+
const highSurrogate = String.fromCharCode(0xd800);
68+
const lowSurrogate = String.fromCharCode(0xdc00);
6969
expect(isUtf8(highSurrogate + lowSurrogate)).toBe(true);
70-
70+
7171
// Test with real emoji
7272
expect(isUtf8('👨‍💻')).toBe(true); // Complex emoji with ZWJ
7373
expect(isUtf8('🏳️‍🌈')).toBe(true); // Rainbow flag emoji
7474
});
7575

7676
test('handles sequences correctly', () => {
77-
const highSurrogate = String.fromCharCode(0xD800);
78-
const lowSurrogate = String.fromCharCode(0xDC00);
77+
const highSurrogate = String.fromCharCode(0xd800);
78+
const lowSurrogate = String.fromCharCode(0xdc00);
7979
const validPair = highSurrogate + lowSurrogate;
80-
80+
8181
expect(isUtf8(validPair + validPair)).toBe(true); // Two valid pairs
8282
expect(isUtf8(validPair + highSurrogate)).toBe(false); // Valid pair + unpaired high
8383
expect(isUtf8('hello' + validPair + 'world')).toBe(true); // Valid pair in middle
@@ -93,11 +93,11 @@ describe('String format validation utilities', () => {
9393
test('delegates to isUtf8 for utf8 format', () => {
9494
expect(validateStringFormat('hello', 'utf8')).toBe(true);
9595
expect(validateStringFormat('héllo', 'utf8')).toBe(true);
96-
expect(validateStringFormat(String.fromCharCode(0xD800), 'utf8')).toBe(false);
96+
expect(validateStringFormat(String.fromCharCode(0xd800), 'utf8')).toBe(false);
9797
});
9898

9999
test('returns true for invalid format (defensive)', () => {
100100
expect(validateStringFormat('hello', 'invalid' as any)).toBe(true);
101101
});
102102
});
103-
});
103+
});

src/util/stringFormats.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const isAscii = (str: string): boolean => {
2121
* Validates if a string represents valid UTF-8 when encoded.
2222
* JavaScript strings are UTF-16, but we need to validate they don't contain
2323
* invalid Unicode sequences that would produce invalid UTF-8.
24-
*
24+
*
2525
* This checks for:
2626
* - Unpaired surrogates (invalid UTF-16 sequences)
2727
* - Characters that would produce invalid UTF-8
@@ -30,19 +30,19 @@ export const isUtf8 = (str: string): boolean => {
3030
const length = str.length;
3131
for (let i = 0; i < length; i++) {
3232
const code = str.charCodeAt(i);
33-
33+
3434
// Check for high surrogate
35-
if (code >= 0xD800 && code <= 0xDBFF) {
35+
if (code >= 0xd800 && code <= 0xdbff) {
3636
// High surrogate must be followed by low surrogate
3737
if (i + 1 >= length) {
3838
return false; // Unpaired high surrogate at end
3939
}
4040
const nextCode = str.charCodeAt(i + 1);
41-
if (nextCode < 0xDC00 || nextCode > 0xDFFF) {
41+
if (nextCode < 0xdc00 || nextCode > 0xdfff) {
4242
return false; // High surrogate not followed by low surrogate
4343
}
4444
i++; // Skip the low surrogate
45-
} else if (code >= 0xDC00 && code <= 0xDFFF) {
45+
} else if (code >= 0xdc00 && code <= 0xdfff) {
4646
// Low surrogate without preceding high surrogate
4747
return false;
4848
}
@@ -63,4 +63,4 @@ export const validateStringFormat = (str: string, format: 'ascii' | 'utf8'): boo
6363
default:
6464
return true;
6565
}
66-
};
66+
};

0 commit comments

Comments
 (0)