Skip to content

Commit 2da90e3

Browse files
committed
feat: lines
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent b210dbe commit 2da90e3

File tree

24 files changed

+420
-4
lines changed

24 files changed

+420
-4
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ Wrap a string
2121
- [Install](#install)
2222
- [Use](#use)
2323
- [API](#api)
24+
- [`lines(thing, config[, options])`](#linesthing-config-options)
2425
- [Types](#types)
2526
- [`Config`](#config)
27+
- [`LinePadding`](#linepadding)
28+
- [`LinesInfo`](#linesinfo)
2629
- [`Options`](#options)
2730
- [`ToString<[T]>`](#tostringt)
2831
- [Contribute](#contribute)
@@ -80,7 +83,27 @@ bun add @flex-development/string-wrap
8083

8184
## API
8285

83-
**TODO**: api
86+
### `lines(thing, config[, options])`
87+
88+
Get info about the lines of a wrapped string.
89+
90+
#### Overloads
91+
92+
- `lines(thing: unknown, config: number | string, options?: Options | null | undefined): LinesInfo`
93+
- `lines(thing: unknown, config: Config | number | string): LinesInfo`
94+
95+
##### Parameters
96+
97+
- `thing` (`unknown`)
98+
— the thing to wrap. non-string values will be converted to strings
99+
- `config` ([`Config`](#config) | `number` | `string`)
100+
— the wrap configuration or the number of columns to wrap the string to
101+
- `options` ([`Options`](#options) | `null` | `undefined`, `optional`)
102+
— options for wrapping
103+
104+
##### Returns
105+
106+
([`LinesInfo`](#linesinfo)) Info about the lines forming the wrapped string
84107

85108
## Types
86109

@@ -99,12 +122,38 @@ String wrapping configuration (`interface`).
99122
- `columns` (`number` | `string`)
100123
— the number of columns to wrap the string to
101124

125+
### `LinePadding`
126+
127+
The strings used to pad either side of each line (`type`).
128+
129+
```ts
130+
type LinePadding = [left: string, right: string]
131+
```
132+
133+
### `LinesInfo`
134+
135+
Info about the lines of a wrapped string (`interface`).
136+
137+
#### Properties
138+
139+
- `eol` (`string`)
140+
— the character, or characters, used to mark the end of a line
141+
- `indent` (`string`)
142+
— the string used to indent each line
143+
- `lines` (`readonly string[]`)
144+
— the list of lines forming the wrapped string
145+
- `padding` ([`LinePadding`](#linepadding))
146+
— the strings used to pad either side of each line
147+
102148
### `Options`
103149
104150
Options for wrapping a string (`interface`).
105151
106152
#### Properties
107153
154+
- `eol?` (`string` | `null` | `undefined`, optional)
155+
— the character, or characters, used to mark the end of a line
156+
- default: `'\n'`
108157
- `fill?` (`boolean` | `null` | `undefined`, optional)
109158
— whether to completely fill each column, splitting words as necessary.\
110159
by default, splits are made at spaces, ensuring that words aren't broken

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
"string-wrap": "./src/internal/*.mts",
6161
"default": "./dist/internal/*.mjs"
6262
},
63+
"#lib/*": {
64+
"string-wrap": "./src/lib/*.mts",
65+
"default": "./dist/lib/*.mjs"
66+
},
6367
"#tests/*": "./__tests__/*.mts",
6468
"#types/*": {
6569
"string-wrap": "./src/types/*.mts",
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`e2e:string-wrap > should expose public api 1`] = `[]`;
3+
exports[`e2e:string-wrap > should expose public api 1`] = `
4+
[
5+
"lines",
6+
]
7+
`;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`e2e:string-wrap > should expose public api 1`] = `[]`;
3+
exports[`e2e:string-wrap > should expose public api 1`] = `
4+
[
5+
"lines",
6+
]
7+
`;

src/index.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
*/
55

66
export type * from '#interfaces/index'
7+
export * from '#lib/index'
78
export type * from '#types/index'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @file Type Tests - LinesInfo
3+
* @module string-wrap/interfaces/tests/unit-d/LinesInfo
4+
*/
5+
6+
import type TestSubject from '#interfaces/lines-info'
7+
import type { LinePadding } from '@flex-development/string-wrap'
8+
9+
describe('unit-d:interfaces/LinesInfo', () => {
10+
it('should match [eol: string]', () => {
11+
expectTypeOf<TestSubject>().toHaveProperty('eol').toEqualTypeOf<string>()
12+
})
13+
14+
it('should match [indent: string]', () => {
15+
expectTypeOf<TestSubject>().toHaveProperty('indent').toEqualTypeOf<string>()
16+
})
17+
18+
it('should match [lines: readonly string[]]', () => {
19+
expectTypeOf<TestSubject>()
20+
.toHaveProperty('lines')
21+
.toEqualTypeOf<readonly string[]>()
22+
})
23+
24+
it('should match [padding: LinePadding]', () => {
25+
expectTypeOf<TestSubject>()
26+
.toHaveProperty('padding')
27+
.toEqualTypeOf<LinePadding>()
28+
})
29+
})

src/interfaces/__tests__/options.spec-d.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ describe('unit-d:interfaces/Options', () => {
1212
expectTypeOf<OptionalKeys<TestSubject>>().toEqualTypeOf<keyof TestSubject>()
1313
})
1414

15+
it('should match [eol?: string | null | undefined]', () => {
16+
expectTypeOf<TestSubject>()
17+
.toHaveProperty('eol')
18+
.toEqualTypeOf<Nilable<string>>()
19+
})
20+
1521
it('should match [fill?: boolean | null | undefined]', () => {
1622
expectTypeOf<TestSubject>()
1723
.toHaveProperty('fill')

src/interfaces/index.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
*/
55

66
export type { default as Config } from '#interfaces/config'
7+
export type { default as LinesInfo } from '#interfaces/lines-info'
78
export type { default as Options } from '#interfaces/options'

src/interfaces/lines-info.mts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file Interfaces - LinesInfo
3+
* @module string-wrap/interfaces/LinesInfo
4+
*/
5+
6+
import type { LinePadding } from '@flex-development/string-wrap'
7+
8+
/**
9+
* Info about the lines of a wrapped string.
10+
*/
11+
interface LinesInfo {
12+
/**
13+
* The character, or characters, used to mark the end of a line.
14+
*/
15+
eol: string
16+
17+
/**
18+
* The string used to indent each line.
19+
*/
20+
indent: string
21+
22+
/**
23+
* The list of lines forming the wrapped string.
24+
*/
25+
lines: readonly string[]
26+
27+
/**
28+
* The strings used to pad either side of each line.
29+
*
30+
* @see {@linkcode LinePadding}
31+
*/
32+
padding: LinePadding
33+
}
34+
35+
export type { LinesInfo as default }

src/interfaces/options.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import type { ToString } from '@flex-development/string-wrap'
99
* Options for wrapping a string.
1010
*/
1111
interface Options {
12+
/**
13+
* The character, or characters, used to mark the end of a line.
14+
*
15+
* @default '\n'
16+
*/
17+
eol?: string | null | undefined
18+
1219
/**
1320
* Whether to completely fill each column, splitting words as necessary.
1421
*

0 commit comments

Comments
 (0)