Skip to content

Commit fb443ed

Browse files
committed
feat: eol
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 63bf539 commit fb443ed

10 files changed

Lines changed: 137 additions & 1 deletion

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ In browsers with [`esm.sh`][esmsh]:
8080
## Types
8181

8282
This package is fully typed with [TypeScript][].
83-
It exports no additional types.
8483

8584
## Project
8685

src/__snapshots__/edge-runtime/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`e2e:mark-util-character > should expose public api 1`] = `
44
[
5+
"eol",
56
"eos",
67
"htab",
78
"is",

src/__snapshots__/happy-dom/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`e2e:mark-util-character > should expose public api 1`] = `
44
[
5+
"eol",
56
"eos",
67
"htab",
78
"is",

src/__snapshots__/node/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`e2e:mark-util-character > should expose public api 1`] = `
44
[
5+
"eol",
56
"eos",
67
"htab",
78
"is",

src/__tests__/eol.spec.mts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @file Unit Tests - eol
3+
* @module mark-util-character/tests/unit/eol
4+
*/
5+
6+
import { codes } from '@flex-development/mark-util-symbol'
7+
import testSubject from '../eol.mts'
8+
9+
describe('unit:eol', () => {
10+
it('should return `false` if `code` is not line ending code', () => {
11+
expect(testSubject(codes.space)).to.be.false
12+
})
13+
14+
it.each<[keyof typeof codes]>([
15+
['cr'],
16+
['crlf'],
17+
['lf'],
18+
['ls'],
19+
['ps'],
20+
['vcr'],
21+
['vlf']
22+
])('should return `true` if `code` is line ending code (`codes.%s`)', key => {
23+
expect(testSubject(codes[key])).to.be.true
24+
})
25+
})

src/eol.mts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file eol
3+
* @module mark-util-character/eol
4+
*/
5+
6+
import type { LineEnding } from '@flex-development/mark-util-character'
7+
import { codes } from '@flex-development/mark-util-symbol'
8+
9+
/**
10+
* Check if `code` represents a line ending.
11+
*
12+
* @see {@linkcode LineEnding}
13+
*
14+
* @this {void}
15+
*
16+
* @param {unknown} code
17+
* The character code to check
18+
* @return {code is LineEnding}
19+
* `true` if `code` is line ending code, `false` otherwise
20+
*/
21+
function eol(this: void, code: unknown): code is LineEnding {
22+
switch (code) {
23+
case codes.cr:
24+
case codes.crlf:
25+
case codes.lf:
26+
case codes.ls:
27+
case codes.ps:
28+
case codes.vcr:
29+
case codes.vlf:
30+
return true
31+
default:
32+
return false
33+
}
34+
}
35+
36+
export default eol

src/index.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* @module mark-util-character
44
*/
55

6+
export { default as eol } from './eol.mts'
67
export { default as eos } from './eos.mts'
78
export { default as htab } from './htab.mts'
89
export { default as is, default as isCode } from './is.mts'
10+
export type * from './types/index.mts'
911
export { default as vtab } from './vtab.mts'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file Type Tests - LineEnding
3+
* @module mark-util-character/types/tests/unit-d/LineEnding
4+
*/
5+
6+
import type { codes } from '@flex-development/mark-util-symbol'
7+
import type TestSubject from '../line-ending.mts'
8+
9+
describe('unit-d:types/LineEnding', () => {
10+
it('should extract typeof codes.cr', () => {
11+
expectTypeOf<TestSubject>().extract<typeof codes.cr>().not.toBeNever()
12+
})
13+
14+
it('should extract typeof codes.crlf', () => {
15+
expectTypeOf<TestSubject>().extract<typeof codes.crlf>().not.toBeNever()
16+
})
17+
18+
it('should extract typeof codes.lf', () => {
19+
expectTypeOf<TestSubject>().extract<typeof codes.lf>().not.toBeNever()
20+
})
21+
22+
it('should extract typeof codes.ls', () => {
23+
expectTypeOf<TestSubject>().extract<typeof codes.ls>().not.toBeNever()
24+
})
25+
26+
it('should extract typeof codes.ps', () => {
27+
expectTypeOf<TestSubject>().extract<typeof codes.ps>().not.toBeNever()
28+
})
29+
30+
it('should extract typeof codes.vcr', () => {
31+
expectTypeOf<TestSubject>().extract<typeof codes.vcr>().not.toBeNever()
32+
})
33+
34+
it('should extract typeof codes.vlf', () => {
35+
expectTypeOf<TestSubject>().extract<typeof codes.vlf>().not.toBeNever()
36+
})
37+
})

src/types/index.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file Entry Point - Type Aliases
3+
* @module mark-util-character/types
4+
*/
5+
6+
export type { default as LineEnding } from './line-ending.mts'

src/types/line-ending.mts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @file Type Aliases - LineEnding
3+
* @module mark-util-character/types/LineEnding
4+
*/
5+
6+
import type { codes } from '@flex-development/mark-util-symbol'
7+
8+
/**
9+
* Union of codes representing a line ending.
10+
*
11+
* @see {@linkcode codes.cr}
12+
* @see {@linkcode codes.crlf}
13+
* @see {@linkcode codes.lf}
14+
* @see {@linkcode codes.ls}
15+
* @see {@linkcode codes.ps}
16+
* @see {@linkcode codes.vcr}
17+
* @see {@linkcode codes.vlf}
18+
*/
19+
type LineEnding =
20+
| typeof codes.cr
21+
| typeof codes.crlf
22+
| typeof codes.lf
23+
| typeof codes.ls
24+
| typeof codes.ps
25+
| typeof codes.vcr
26+
| typeof codes.vlf
27+
28+
export type { LineEnding as default }

0 commit comments

Comments
 (0)