Skip to content

Commit e04ad31

Browse files
feat: add namespaces module (+ small fixes) (#108)
1 parent cb1d0d6 commit e04ad31

File tree

6 files changed

+117
-77
lines changed

6 files changed

+117
-77
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## 1.1.0 (Unreleased)
4+
### Features
5+
- A new module under `./constants`, which exports constants of XML namespaces
6+
```diff
7+
+ export const namespaceHtml = 'http://www.w3.org/1999/xhtml'
8+
+ export const namespaceMathMl = 'http://www.w3.org/1998/Math/MathML'
9+
+ export const namespaceSvg = 'http://www.w3.org/2000/svg'
10+
+ export const namespaceXLink = 'http://www.w3.org/1999/xlink'
11+
+ export const namespaceXml = 'http://www.w3.org/XML/1998/namespace'
12+
+ export const namespaceXmlNs = 'http://www.w3.org/2000/xmlns/'
13+
```
14+
15+
### Documentation
16+
- Improve JSR.io's rendering of `@see` annotations which references external links
17+
18+
### Deprecated
19+
- `isAsciiWhitespace()` is deprecated. Use `isAsciiWsp()` instead.
20+
321
## 1.0.1 (2025-05-02)
422
- Fix minor rendering issue in README.md for jsr.io
523

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
[![Codecov](https://img.shields.io/codecov/c/github/nc-js/whatwg-infra?style=flat-square&logo=codecov&logoColor=%23fff)](https://codecov.io/gh/nc-js/whatwg-infra)
55
[![CI status](https://img.shields.io/github/actions/workflow/status/nc-js/whatwg-infra/.github%2Fworkflows%2Fdeno-ci.yml?style=flat-square)](https://github.com/nc-js/whatwg-infra/actions/workflows/deno-ci.yml)
66

7-
A small TypeScript package implementing various Unicode-related algorithms from the [**WHATWG Infra Standard**](https://infra.spec.whatwg.org/). This currently includes:
7+
A small TypeScript package implementing various algorithms from the [**WHATWG Infra Standard**](https://infra.spec.whatwg.org/). This currently includes:
88
- [§ 4.5 Code points](https://infra.spec.whatwg.org/#code-points)
99
- [§ 4.6 Strings](https://infra.spec.whatwg.org/#strings)
10+
- [§ 8 Namespaces](https://infra.spec.whatwg.org/#namespaces)
1011

1112
## License
1213

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"exports": {
1313
"./codePoints": "./src/codePoints.ts",
14-
"./strings": "./src/strings.ts"
14+
"./strings": "./src/strings.ts",
15+
"./namespaces": "./src/namespaces.ts"
1516
},
1617
"fmt": {
1718
"include": [

src/codePoints.ts

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const isCodePointBetween = (
2222
* A code point that exists between 0 (`0x0000` NUL)
2323
* and 127 (`0x007F` DEL).
2424
*
25-
* @see https://infra.spec.whatwg.org/#ascii-byte
25+
* @see {@link https://infra.spec.whatwg.org/#ascii-byte}
2626
*/
2727
export const isAscii = (v: string): boolean => isCodePointBetween(v, 0x00, 0x7F)
2828

@@ -31,7 +31,7 @@ export const isAscii = (v: string): boolean => isCodePointBetween(v, 0x00, 0x7F)
3131
* - `U+D800` HIGH SURROGATES
3232
* - `U+DFFF` LOW SURROGATES
3333
*
34-
* @see https://infra.spec.whatwg.org/#surrogate
34+
* @see {@link https://infra.spec.whatwg.org/#surrogate}
3535
*/
3636
export const isSurrogate = (v: string): boolean => {
3737
for (const codePoint of v) {
@@ -46,8 +46,8 @@ export const isSurrogate = (v: string): boolean => {
4646
/**
4747
* A code point that is not a Unicode surrogate.
4848
*
49-
* @see https://infra.spec.whatwg.org/#surrogate
50-
* @see https://infra.spec.whatwg.org/#scalar-value
49+
* @see {@link https://infra.spec.whatwg.org/#surrogate}
50+
* @see {@link https://infra.spec.whatwg.org/#scalar-value}
5151
*/
5252
export const isScalarValue = (v: string): boolean => !isSurrogate(v)
5353

@@ -65,40 +65,14 @@ export const isScalarValue = (v: string): boolean => !isSurrogate(v)
6565
*/
6666
export const isNonCharacter = (v: string): boolean => {
6767
return isCodePointBetween(v, 0xFDD0, 0xFDEF) ||
68+
// deno-fmt-ignore
6869
[
69-
0xFFFE,
70-
0xFFFF,
71-
0x1FFFE,
72-
0x1FFFF,
73-
0x2FFFE,
74-
0x2FFFF,
75-
0x3FFFE,
76-
0x3FFFF,
77-
0x4FFFE,
78-
0x4FFFF,
79-
0x5FFFE,
80-
0x5FFFF,
81-
0x6FFFE,
82-
0x6FFFF,
83-
0x7FFFE,
84-
0x7FFFF,
85-
0x8FFFE,
86-
0x8FFFF,
87-
0x9FFFE,
88-
0x9FFFF,
89-
0xAFFFE,
90-
0xAFFFF,
91-
0xBFFFE,
92-
0xBFFFF,
93-
0xCFFFE,
94-
0xCFFFF,
95-
0xDFFFE,
96-
0xDFFFF,
97-
0xEFFFE,
98-
0xEFFFF,
99-
0xFFFFE,
100-
0xFFFFF,
101-
0x10FFFE,
70+
0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
71+
0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF,
72+
0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF,
73+
0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF,
74+
0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF,
75+
0xFFFFE, 0xFFFFF, 0x10FFFE,
10276
].includes(v.codePointAt(0) as number)
10377
}
10478

@@ -108,7 +82,7 @@ export const isNonCharacter = (v: string): boolean => {
10882
* - `U+000A` EOL, LF, NL - End of line
10983
* - `U+000D` CR - Carriage return
11084
*
111-
* @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
85+
* @see {@link https://infra.spec.whatwg.org/#ascii-tab-or-newline}
11286
*/
11387
export const isAsciiTabOrNewline = (v: string): boolean =>
11488
v === '\u{0009}' || v === '\u{000A}' || v === '\u{000D}'
@@ -117,27 +91,37 @@ export const isAsciiTabOrNewline = (v: string): boolean =>
11791
* A code point that's either an ASCII tab or newline,
11892
* `U+000C` FF Form Feed, or `U+0020` SP Space.
11993
*
120-
* @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
121-
* @see https://infra.spec.whatwg.org/#ascii-whitespace
94+
* @see {@link https://infra.spec.whatwg.org/#ascii-tab-or-newline}
95+
* @see {@link https://infra.spec.whatwg.org/#ascii-whitespace}
12296
*/
123-
export const isAsciiWhitespace = (v: string): boolean =>
97+
export const isAsciiWsp = (v: string): boolean =>
12498
isAsciiTabOrNewline(v) || v === '\u{000C}' || v === '\u{0020}'
12599

100+
/**
101+
* A code point that's either an ASCII tab or newline,
102+
* `U+000C` FF Form Feed, or `U+0020` SP Space.
103+
*
104+
* @see {@link https://infra.spec.whatwg.org/#ascii-tab-or-newline}
105+
* @see {@link https://infra.spec.whatwg.org/#ascii-whitespace}
106+
* @deprecated Use `isAsciiWsp()` instead.
107+
*/
108+
export const isAsciiWhitespace = (v: string): boolean => isAsciiWsp(v)
109+
126110
/**
127111
* A code point inclusively between the range of:
128112
* - `U+0000` NULL
129113
* - `U+001F` INFORMATION SEPARATOR ONE
130114
*
131-
* @see https://infra.spec.whatwg.org/#c0-control
115+
* @see {@link https://infra.spec.whatwg.org/#c0-control}
132116
*/
133117
export const isC0Control = (v: string): boolean =>
134118
isCodePointBetween(v, 0x0000, 0x001F)
135119

136120
/**
137121
* A code point that's either a C0 control or U+0020 SPACE.
138122
*
139-
* @see https://infra.spec.whatwg.org/#c0-control
140-
* @see https://infra.spec.whatwg.org/#c0-control-or-space
123+
* @see {@link https://infra.spec.whatwg.org/#c0-control}
124+
* @see {@link https://infra.spec.whatwg.org/#c0-control-or-space}
141125
*/
142126
export const isC0ControlOrSpace = (v: string): boolean =>
143127
isC0Control(v) || v === '\u{0020}'
@@ -148,8 +132,8 @@ export const isC0ControlOrSpace = (v: string): boolean =>
148132
* - `U+007F` DELETE
149133
* - `U+009F` APPLICATION PROGRAMMING COMMAND
150134
*
151-
* @see https://infra.spec.whatwg.org/#c0-control
152-
* @see https://infra.spec.whatwg.org/#control
135+
* @see {@link https://infra.spec.whatwg.org/#c0-control}
136+
* @see {@link https://infra.spec.whatwg.org/#control}
153137
*/
154138
export const isControl = (v: string): boolean =>
155139
isC0Control(v) || isCodePointBetween(v, 0x007F, 0x009F)
@@ -158,7 +142,7 @@ export const isControl = (v: string): boolean =>
158142
* A code point that is inclusively between the range of
159143
* `U+0030` (0) and `U+0039` (9).
160144
*
161-
* @see https://infra.spec.whatwg.org/#ascii-digit
145+
* @see {@link https://infra.spec.whatwg.org/#ascii-digit}
162146
*/
163147
export const isAsciiDigit = (v: string): boolean =>
164148
isCodePointBetween(v, 0x0030, 0x0039)
@@ -167,25 +151,25 @@ export const isAsciiDigit = (v: string): boolean =>
167151
* A code point that is inclusively between the range of
168152
* `U+0041` (A) and `U+0046` (F).
169153
*
170-
* @see https://infra.spec.whatwg.org/#ascii-upper-hex-digit
154+
* @see {@link https://infra.spec.whatwg.org/#ascii-upper-hex-digit}
171155
*/
172156
export const isAsciiUpperHexDigit = (v: string): boolean =>
173157
isCodePointBetween(v, 0x0041, 0x0046)
174158

175159
/**
176160
* A code point that is inclusively between the range of
177161
* `U+0061` (a) and `U+0066` (f).
178-
* @see https://infra.spec.whatwg.org/#ascii-lower-hex-digit
162+
* @see {@link https://infra.spec.whatwg.org/#ascii-lower-hex-digit}
179163
*/
180164
export const isAsciiLowerHexDigit = (v: string): boolean =>
181165
isCodePointBetween(v, 0x0061, 0x0066)
182166

183167
/**
184168
* A code point that is either an ASCII lower or upper hex digit.
185169
*
186-
* @see https://infra.spec.whatwg.org/#ascii-upper-hex-digit
187-
* @see https://infra.spec.whatwg.org/#ascii-lower-hex-digit
188-
* @see https://infra.spec.whatwg.org/#ascii-hex-digit
170+
* @see {@link https://infra.spec.whatwg.org/#ascii-upper-hex-digit}
171+
* @see {@link https://infra.spec.whatwg.org/#ascii-lower-hex-digit}
172+
* @see {@link https://infra.spec.whatwg.org/#ascii-hex-digit}
189173
*/
190174
export const isAsciiHexDigit = (v: string): boolean =>
191175
isAsciiLowerHexDigit(v) || isAsciiUpperHexDigit(v)
@@ -194,7 +178,7 @@ export const isAsciiHexDigit = (v: string): boolean =>
194178
* A code point that is inclusively between the range of
195179
* `U+0041` (A) and `U+005A` (Z).
196180
*
197-
* @see https://infra.spec.whatwg.org/#ascii-upper-alpha
181+
* @see {@link https://infra.spec.whatwg.org/#ascii-upper-alpha}
198182
*/
199183
export const isAsciiUpperAlpha = (v: string): boolean =>
200184
isCodePointBetween(v, 0x0041, 0x005A)
@@ -203,7 +187,7 @@ export const isAsciiUpperAlpha = (v: string): boolean =>
203187
* A code point that is inclusively between the range of
204188
* `U+0061` (a) and `U+007A` (z).
205189
*
206-
* @see https://infra.spec.whatwg.org/#ascii-lower-alpha
190+
* @see {@link https://infra.spec.whatwg.org/#ascii-lower-alpha}
207191
*/
208192
export const isAsciiLowerAlpha = (v: string): boolean =>
209193
isCodePointBetween(v, 0x0061, 0x007A)
@@ -212,18 +196,18 @@ export const isAsciiLowerAlpha = (v: string): boolean =>
212196
* A code point that is either an ASCII lower alpha or
213197
* ASCII upper alpha.
214198
*
215-
* @see https://infra.spec.whatwg.org/#ascii-lower-alpha
216-
* @see https://infra.spec.whatwg.org/#ascii-upper-alpha
217-
* @see https://infra.spec.whatwg.org/#ascii-alpha
199+
* @see {@link https://infra.spec.whatwg.org/#ascii-lower-alpha}
200+
* @see {@link https://infra.spec.whatwg.org/#ascii-upper-alpha}
201+
* @see {@link https://infra.spec.whatwg.org/#ascii-alpha}
218202
*/
219203
export const isAsciiAlpha = (v: string): boolean =>
220204
isAsciiLowerAlpha(v) || isAsciiUpperAlpha(v)
221205

222206
/**
223207
* A code point that is an ASCII digit or ASCII alpha.
224208
*
225-
* @see https://infra.spec.whatwg.org/#ascii-numeric
226-
* @see https://infra.spec.whatwg.org/#ascii-alpha
209+
* @see {{@link https://infra.spec.whatwg.org/#ascii-numeric}
210+
* @see {{@link https://infra.spec.whatwg.org/#ascii-alpha}
227211
*/
228212
export const isAsciiAlphanumeric = (v: string): boolean =>
229213
isAsciiDigit(v) || isAsciiAlpha(v)

src/namespaces.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* The XML namespace for HTML
3+
* @see {@link https://infra.spec.whatwg.org/#html-namespace}
4+
*/
5+
export const namespaceHtml = 'http://www.w3.org/1999/xhtml'
6+
7+
/**
8+
* The XML namespace for MathML
9+
* @see {@link https://infra.spec.whatwg.org/#mathml-namespace}
10+
*/
11+
export const namespaceMathMl = 'http://www.w3.org/1998/Math/MathML'
12+
13+
/**
14+
* The XML namespace for SVG
15+
* @see {@link https://infra.spec.whatwg.org/#svg-namespace}
16+
*/
17+
export const namespaceSvg = 'http://www.w3.org/2000/svg'
18+
19+
/**
20+
* The XML namespace for XML Link (XML Linking Language)
21+
* @see {@link https://infra.spec.whatwg.org/#xlink-namespace}
22+
* @see {@link https://www.w3.org/TR/xlink/}
23+
*/
24+
export const namespaceXLink = 'http://www.w3.org/1999/xlink'
25+
26+
/**
27+
* The XML namespace for XML
28+
* @see {@link https://infra.spec.whatwg.org/#xml-namespace}
29+
*/
30+
export const namespaceXml = 'http://www.w3.org/XML/1998/namespace'
31+
32+
/**
33+
* The XML namespace for XMLNS
34+
* @see {@link https://infra.spec.whatwg.org/#xmlns-namespace}
35+
*/
36+
export const namespaceXmlNs = 'http://www.w3.org/2000/xmlns/'

0 commit comments

Comments
 (0)