Skip to content

Commit fe29fd6

Browse files
authored
Add a single-line-text utility schema (#62)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent f186bfa commit fe29fd6

3 files changed

Lines changed: 359 additions & 25 deletions

File tree

meta/schemas.json

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,13 @@
55
"properties": {
66
"$id": false,
77
"$comment": {
8-
"$ref": "#/$defs/clean-prose"
8+
"$ref": "../schemas/misc/single-line-text.json"
99
},
1010
"title": {
11-
"$ref": "#/$defs/clean-prose"
11+
"$ref": "../schemas/misc/single-line-text.json"
1212
},
1313
"description": {
14-
"$ref": "#/$defs/clean-prose"
15-
}
16-
},
17-
"$defs": {
18-
"clean-prose": {
19-
"type": "string",
20-
"not": {
21-
"anyOf": [
22-
{
23-
"pattern": "\\.$"
24-
},
25-
{
26-
"pattern": " \\s"
27-
},
28-
{
29-
"pattern": "[\\n\\r\\t]"
30-
},
31-
{
32-
"pattern": "[\\x00-\\x1F\\x7F]"
33-
}
34-
]
35-
},
36-
"pattern": "^[^\\s].*[^\\s]$|^[^\\s]$"
14+
"$ref": "../schemas/misc/single-line-text.json"
3715
}
3816
}
3917
}

schemas/misc/single-line-text.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "Single-line Text",
4+
"description": "A string representing a single line of clean text without leading or trailing whitespace, excessive internal spacing, non-printable characters, newlines, tabs, trailing periods, or other punctuation issues",
5+
"examples": [
6+
"This is a simple text",
7+
"Multiple sentences work fine",
8+
"Numbers and symbols: 123 $%&",
9+
"Unicode characters are allowed: café, 日本語"
10+
],
11+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
12+
"x-links": [ "https://en.wikipedia.org/wiki/String_(computer_science)" ],
13+
"type": "string",
14+
"pattern": "^(?!.*\\.$)(?!.*(?<!\\.)\\.\\.(?!\\.))(?!.* [.,;:!?])(?![?!])(?!.*[?!])(?!.* )(?!.*\\(\\))(?!.*\\[\\])(?!.*--)(?!.*[\\n\\r\\t])(?!.*[\\x00-\\x1F\\x7F])[^\\s](?:.*[^\\s])?$"
15+
}
Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
{
2+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
3+
"target": "../../schemas/misc/single-line-text.json",
4+
"tests": [
5+
{
6+
"description": "Valid - simple text",
7+
"data": "This is valid text",
8+
"valid": true
9+
},
10+
{
11+
"description": "Valid - single word",
12+
"data": "Word",
13+
"valid": true
14+
},
15+
{
16+
"description": "Valid - single character",
17+
"data": "a",
18+
"valid": true
19+
},
20+
{
21+
"description": "Valid - text with single spaces",
22+
"data": "Multiple words with spaces",
23+
"valid": true
24+
},
25+
{
26+
"description": "Invalid - two consecutive spaces",
27+
"data": "Two spaces",
28+
"valid": false
29+
},
30+
{
31+
"description": "Valid - numbers and symbols",
32+
"data": "Text with 123 and $%& symbols",
33+
"valid": true
34+
},
35+
{
36+
"description": "Valid - Unicode characters",
37+
"data": "café 日本語 emoji 🎉",
38+
"valid": true
39+
},
40+
{
41+
"description": "Valid - multiple sentences without trailing period",
42+
"data": "First sentence. Second sentence. Third one",
43+
"valid": true
44+
},
45+
{
46+
"description": "Valid - text with period in middle",
47+
"data": "Dr. Smith works here",
48+
"valid": true
49+
},
50+
{
51+
"description": "Valid - abbreviations",
52+
"data": "U.S.A. and U.K. are countries",
53+
"valid": true
54+
},
55+
{
56+
"description": "Invalid - trailing period",
57+
"data": "Text with trailing period.",
58+
"valid": false
59+
},
60+
{
61+
"description": "Invalid - just a period",
62+
"data": ".",
63+
"valid": false
64+
},
65+
{
66+
"description": "Invalid - leading whitespace",
67+
"data": " Leading space",
68+
"valid": false
69+
},
70+
{
71+
"description": "Invalid - trailing whitespace",
72+
"data": "Trailing space ",
73+
"valid": false
74+
},
75+
{
76+
"description": "Invalid - leading tab",
77+
"data": "\tTabbed text",
78+
"valid": false
79+
},
80+
{
81+
"description": "Invalid - trailing tab",
82+
"data": "Text with tab\t",
83+
"valid": false
84+
},
85+
{
86+
"description": "Invalid - tab in middle",
87+
"data": "Text with\ttab",
88+
"valid": false
89+
},
90+
{
91+
"description": "Invalid - newline in middle",
92+
"data": "Text with\nnewline",
93+
"valid": false
94+
},
95+
{
96+
"description": "Invalid - carriage return in middle",
97+
"data": "Text with\rcarriage return",
98+
"valid": false
99+
},
100+
{
101+
"description": "Invalid - multiple newlines",
102+
"data": "Line one\nLine two\nLine three",
103+
"valid": false
104+
},
105+
{
106+
"description": "Invalid - three consecutive spaces",
107+
"data": "Three spaces",
108+
"valid": false
109+
},
110+
{
111+
"description": "Invalid - four consecutive spaces",
112+
"data": "Four spaces",
113+
"valid": false
114+
},
115+
{
116+
"description": "Invalid - many consecutive spaces",
117+
"data": "Many spaces",
118+
"valid": false
119+
},
120+
{
121+
"description": "Invalid - null character",
122+
"data": "Text with\u0000null",
123+
"valid": false
124+
},
125+
{
126+
"description": "Invalid - bell character",
127+
"data": "Text with\u0007bell",
128+
"valid": false
129+
},
130+
{
131+
"description": "Invalid - backspace character",
132+
"data": "Text with\bbackspace",
133+
"valid": false
134+
},
135+
{
136+
"description": "Invalid - form feed",
137+
"data": "Text with\fform feed",
138+
"valid": false
139+
},
140+
{
141+
"description": "Invalid - vertical tab",
142+
"data": "Text with\u000Bvertical tab",
143+
"valid": false
144+
},
145+
{
146+
"description": "Invalid - escape character",
147+
"data": "Text with\u001Bescape",
148+
"valid": false
149+
},
150+
{
151+
"description": "Invalid - delete character",
152+
"data": "Text withdelete",
153+
"valid": false
154+
},
155+
{
156+
"description": "Invalid - empty string",
157+
"data": "",
158+
"valid": false
159+
},
160+
{
161+
"description": "Invalid - only whitespace",
162+
"data": " ",
163+
"valid": false
164+
},
165+
{
166+
"description": "Invalid - only tab",
167+
"data": "\t",
168+
"valid": false
169+
},
170+
{
171+
"description": "Invalid - only newline",
172+
"data": "\n",
173+
"valid": false
174+
},
175+
{
176+
"description": "Invalid type - number",
177+
"data": 123,
178+
"valid": false
179+
},
180+
{
181+
"description": "Invalid type - boolean",
182+
"data": true,
183+
"valid": false
184+
},
185+
{
186+
"description": "Invalid type - null",
187+
"data": null,
188+
"valid": false
189+
},
190+
{
191+
"description": "Invalid type - array",
192+
"data": [],
193+
"valid": false
194+
},
195+
{
196+
"description": "Invalid type - object",
197+
"data": {},
198+
"valid": false
199+
},
200+
{
201+
"description": "Invalid - double period",
202+
"data": "Text with.. double period",
203+
"valid": false
204+
},
205+
{
206+
"description": "Invalid - double period at end",
207+
"data": "Text ends here..",
208+
"valid": false
209+
},
210+
{
211+
"description": "Valid - proper ellipsis",
212+
"data": "Text with... ellipsis",
213+
"valid": true
214+
},
215+
{
216+
"description": "Valid - ellipsis in parentheses",
217+
"data": "The duration component accepts designator format (P...) and weeks format (PnW)",
218+
"valid": true
219+
},
220+
{
221+
"description": "Invalid - space before period",
222+
"data": "Text with space .",
223+
"valid": false
224+
},
225+
{
226+
"description": "Invalid - space before comma",
227+
"data": "Text with space ,",
228+
"valid": false
229+
},
230+
{
231+
"description": "Invalid - space before semicolon",
232+
"data": "Text with space ;",
233+
"valid": false
234+
},
235+
{
236+
"description": "Invalid - space before colon",
237+
"data": "Text with space :",
238+
"valid": false
239+
},
240+
{
241+
"description": "Invalid - space before exclamation",
242+
"data": "Text with space !",
243+
"valid": false
244+
},
245+
{
246+
"description": "Invalid - space before question mark",
247+
"data": "Text with space ?",
248+
"valid": false
249+
},
250+
{
251+
"description": "Invalid - question mark at start",
252+
"data": "?This is a question",
253+
"valid": false
254+
},
255+
{
256+
"description": "Invalid - exclamation mark at start",
257+
"data": "!This is excitement",
258+
"valid": false
259+
},
260+
{
261+
"description": "Invalid - question mark in middle",
262+
"data": "Text with ? question mark",
263+
"valid": false
264+
},
265+
{
266+
"description": "Invalid - exclamation mark in middle",
267+
"data": "Text with ! exclamation",
268+
"valid": false
269+
},
270+
{
271+
"description": "Invalid - question mark at end",
272+
"data": "Is this a question?",
273+
"valid": false
274+
},
275+
{
276+
"description": "Invalid - exclamation mark at end",
277+
"data": "This is exciting!",
278+
"valid": false
279+
},
280+
{
281+
"description": "Invalid - double exclamation",
282+
"data": "Very exciting!!",
283+
"valid": false
284+
},
285+
{
286+
"description": "Invalid - double question mark",
287+
"data": "Really??",
288+
"valid": false
289+
},
290+
{
291+
"description": "Invalid - empty parentheses",
292+
"data": "Text with () empty parens",
293+
"valid": false
294+
},
295+
{
296+
"description": "Invalid - empty brackets",
297+
"data": "Text with [] empty brackets",
298+
"valid": false
299+
},
300+
{
301+
"description": "Invalid - double hyphen",
302+
"data": "Text with -- double hyphen",
303+
"valid": false
304+
},
305+
{
306+
"description": "Valid - em dash",
307+
"data": "Text with — em dash",
308+
"valid": true
309+
},
310+
{
311+
"description": "Valid - single hyphen",
312+
"data": "Text with single-hyphen word",
313+
"valid": true
314+
},
315+
{
316+
"description": "Valid - parentheses with content",
317+
"data": "Text with (content) in parens",
318+
"valid": true
319+
},
320+
{
321+
"description": "Valid - brackets with content",
322+
"data": "Text with [content] in brackets",
323+
"valid": true
324+
},
325+
{
326+
"description": "Valid - proper comma usage",
327+
"data": "First item, second item, third item",
328+
"valid": true
329+
},
330+
{
331+
"description": "Valid - proper colon usage",
332+
"data": "Title: Subtitle",
333+
"valid": true
334+
},
335+
{
336+
"description": "Valid - proper semicolon usage",
337+
"data": "First clause; second clause",
338+
"valid": true
339+
}
340+
]
341+
}

0 commit comments

Comments
 (0)