Skip to content

Commit 126e1b2

Browse files
committed
docs: api
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent c486c4a commit 126e1b2

File tree

6 files changed

+129
-10
lines changed

6 files changed

+129
-10
lines changed

README.md

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ File extension regex
1818
- [Install](#install)
1919
- [Use](#use)
2020
- [API](#api)
21+
- [`EXT_DTS_REGEX`](#ext_dts_regex)
22+
- [`EXT_JS_REGEX`](#ext_js_regex)
23+
- [`EXT_JSON_REGEX`](#ext_json_regex)
24+
- [`EXT_TS_REGEX`](#ext_ts_regex)
25+
- [`extRegex(ext[, options])`](#extregexext-options)
2126
- [Types](#types)
2227
- [Interfaces](#interfaces)
2328
- [Related](#related)
@@ -64,7 +69,118 @@ yarn add @flex-development/ext-regex@flex-development/ext-regex
6469

6570
## API
6671

67-
**TODO**: api documentation.
72+
This package exports the following identifiers:
73+
74+
- [`EXT_DTS_REGEX`](#ext_dts_regex)
75+
- [`EXT_JS_REGEX`](#ext_js_regex)
76+
- [`EXT_JSON_REGEX`](#ext_json_regex)
77+
- [`EXT_TS_REGEX`](#ext_ts_regex)
78+
- [`extRegex`](#extregexext-options)
79+
80+
There is no default export.
81+
82+
### `EXT_DTS_REGEX`
83+
84+
TypeScript declaration file extension regex.
85+
86+
Supported extensions:
87+
88+
- `.d.cts`
89+
- `.d.mts`
90+
- `.d.ts`
91+
92+
Named capturing groups:
93+
94+
- `type`: Letter between `'.'` and `'ts'` in file extension
95+
96+
#### Source
97+
98+
> [`src/regex/dts.ts`](src/regex/dts.ts)
99+
100+
### `EXT_JS_REGEX`
101+
102+
JavaScript file extension regex.
103+
104+
Supported extensions:
105+
106+
- `.cjs`
107+
- `.js`
108+
- `.jsx`
109+
- `.mjs`
110+
111+
Named capturing groups:
112+
113+
- `type`: Letter between `'.'` and `'js'` in file extension
114+
115+
#### Source
116+
117+
> [`src/regex/js.ts`](src/regex/js.ts)
118+
119+
### `EXT_JSON_REGEX`
120+
121+
JSON file extension regex.
122+
123+
Supported extensions:
124+
125+
- `.json`
126+
- `.json5`
127+
- `.jsonc`
128+
129+
Named capturing groups:
130+
131+
- `type`: Character after `'json'` in file extension
132+
133+
#### Source
134+
135+
> [`src/regex/json.ts`](src/regex/json.ts)
136+
137+
### `EXT_TS_REGEX`
138+
139+
TypeScript file extension regex.
140+
141+
Supported extensions:
142+
143+
- `.cts`
144+
- `.d.cts`
145+
- `.d.mts`
146+
- `.d.ts`
147+
- `.mts`
148+
- `.ts`
149+
- `.tsx`
150+
151+
Named capturing groups:
152+
153+
- `dts`: Letter `'d'` if extension is [declaration file extension](#ext_dts_regex)
154+
- `type`: Letter between `'.'` and `'ts'` in file extension
155+
156+
#### Source
157+
158+
> [`src/regex/ts.ts`](src/regex/ts.ts)
159+
160+
### `extRegex(ext[, options])`
161+
162+
Creates a regular expression matching the given file extension, `ext`.
163+
164+
The file extension does not need to begin with a dot character (`'.'`). If it doesn't, however, it will be formatted
165+
before being converted into a regular expression pattern. The returned regular expression will match the formatted file
166+
extension instead.
167+
168+
#### Parameters
169+
170+
- `{string}` **`ext`** &mdash; File extension to evaluate
171+
- `{Options?}` **`[options]`** &mdash; Regular expression options
172+
173+
#### Returns
174+
175+
`{RegExp}` Regular expression matching `ext`.
176+
177+
#### Throws
178+
179+
`{errnode.NodeError<TypeError>}` If `ext` is not a string.
180+
181+
#### Source
182+
183+
> [`src/utils/ext-regex.ts`](src/utils/ext-regex.ts)
68184
69185
## Types
70186

src/regex/dts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* - `.d.mts`
1313
* - `.d.ts`
1414
*
15-
* Captured groups:
15+
* Named capturing groups:
1616
*
1717
* - `type`: Letter between `'.'` and `'ts'` in file extension
1818
*

src/regex/js.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file Regular EXPRESSIONS - EXT_JS_REGEX
2+
* @file Regular Expressions - EXT_JS_REGEX
33
* @module ext-regex/regex/js
44
*/
55

@@ -13,7 +13,7 @@
1313
* - `.jsx`
1414
* - `.mjs`
1515
*
16-
* Captured groups:
16+
* Named capturing groups:
1717
*
1818
* - `type`: Letter between `'.'` and `'js'` in file extension
1919
*

src/regex/json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file Regular EXPRESSIONS - EXT_JSON_REGEX
2+
* @file Regular Expressions - EXT_JSON_REGEX
33
* @module ext-regex/regex/json
44
*/
55

@@ -12,7 +12,7 @@
1212
* - `.json5`
1313
* - `.jsonc`
1414
*
15-
* Captured groups:
15+
* Named capturing groups:
1616
*
1717
* - `type`: Character after `'json'` in file extension
1818
*

src/regex/ts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file Regular EXPRESSIONS - EXT_TS_REGEX
2+
* @file Regular Expressions - EXT_TS_REGEX
33
* @module ext-regex/regex/ts
44
*/
55

@@ -16,7 +16,7 @@
1616
* - `.ts`
1717
* - `.tsx`
1818
*
19-
* Captured groups:
19+
* Named capturing groups:
2020
*
2121
* - `dts`: Letter `'d'` if extension is declaration file extension
2222
* - `type`: Letter between `'.'` and `'ts'` in file extension

src/utils/ext-regex.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66
import type { Options } from '#src/interfaces'
77
import * as internal from '#src/internal'
8-
import * as errnode from '@flex-development/errnode'
8+
import type * as errnode from '@flex-development/errnode'
99
import * as pathe from '@flex-development/pathe'
1010
import { isNIL, type LiteralUnion } from '@flex-development/tutils'
1111

1212
/**
1313
* Creates a regular expression matching the given file extension, `ext`.
1414
*
15-
* The file extension need not begin with a dot character (`'.'`).
15+
* The file extension does not need to begin with a dot character (`'.'`). If it
16+
* doesn't, however, it will be formatted before being converted into a regular
17+
* expression pattern. The returned regular expression will match the formatted
18+
* file extension instead.
1619
*
1720
* Throws `ERR_INVALID_ARG_TYPE` if the given file extension is not a string.
1821
*

0 commit comments

Comments
 (0)