Skip to content

Commit e96917c

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

File tree

12 files changed

+164
-0
lines changed

12 files changed

+164
-0
lines changed

.dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
attw
22
cefc
3+
commandoptst
34
commitlintrc
45
dedupe
56
devlop

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Wrap a string
2222
- [Use](#use)
2323
- [API](#api)
2424
- [`lines(thing, config[, options])`](#linesthing-config-options)
25+
- [`wrap(thing, config[, options])`](#wrapthing-config-options)
2526
- [Types](#types)
2627
- [`Config`](#config)
2728
- [`LinePadding`](#linepadding)
@@ -83,6 +84,13 @@ bun add @flex-development/string-wrap
8384

8485
## API
8586

87+
This package exports the following identifiers:
88+
89+
- [`lines`](#linesthing-config-options)
90+
- [`wrap`](#wrapthing-config-options)
91+
92+
The default export is [`wrap`](#wrapthing-config-options).
93+
8694
### `lines(thing, config[, options])`
8795

8896
Get info about the lines of a wrapped string.
@@ -105,6 +113,28 @@ Get info about the lines of a wrapped string.
105113

106114
([`LinesInfo`](#linesinfo)) Info about the lines forming the wrapped string
107115

116+
### `wrap(thing, config[, options])`
117+
118+
Wrap a string to the specified column width.
119+
120+
#### Overloads
121+
122+
- `wrap(thing: unknown, config: number | string, options?: Options | null | undefined): string`
123+
- `wrap(thing: unknown, config: Config | number | string): string`
124+
125+
##### Parameters
126+
127+
- `thing` (`unknown`)
128+
— the thing to wrap. non-string values will be converted to strings
129+
- `config` ([`Config`](#config) | `number` | `string`)
130+
— the wrap configuration or the number of columns to wrap the string to
131+
- `options` ([`Options`](#options) | `null` | `undefined`, `optional`)
132+
— options for wrapping
133+
134+
##### Returns
135+
136+
(`string`) The wrapped string
137+
108138
## Types
109139

110140
This package is fully typed with [TypeScript][].

__fixtures__/parsed-options.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @file Fixtures - parsedOptions
3+
* @module fixtures/parsedOptions
4+
*/
5+
6+
/**
7+
* A long string containing several sequences and a line break.
8+
*
9+
* @type {string}
10+
*/
11+
export default 'Parsed options can be accessed by calling [`.opts<T>()`](#commandoptst) on a [`Command`](#commandinfo) object, and are passed to the command\'s [`action`](#commandactionaction) handler.\nMulti-word options such as `--template-engine` are `camelCased`, becoming `program.opts().templateEngine`, or can be configured to be converted using `snake_case`, becoming `program.opts().template_engine`.'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
exports[`e2e:string-wrap > should expose public api 1`] = `
44
[
55
"lines",
6+
"wrap",
67
]
78
`;

src/__snapshots__/node/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
exports[`e2e:string-wrap > should expose public api 1`] = `
44
[
55
"lines",
6+
"wrap",
67
]
78
`;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
exports[`e2e:lib > should expose public api 1`] = `
44
[
55
"lines",
6+
"wrap",
67
]
78
`;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`unit:lib/wrap > should return wrapped string 1`] = `
4+
"Parsed options can be accessed by calling [\`.opts<T>()\`](#commandoptst)
5+
on a [\`Command\`](#commandinfo) object, and are passed to the command's
6+
[\`action\`](#commandactionaction) handler.
7+
Multi-word options such as \`--template-engine\` are \`camelCased\`,
8+
becoming \`program.opts().templateEngine\`, or can be configured to be
9+
converted using \`snake_case\`, becoming \`program.opts().template_engine\`."
10+
`;

src/lib/__snapshots__/node/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
exports[`e2e:lib > should expose public api 1`] = `
44
[
55
"lines",
6+
"wrap",
67
]
78
`;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`unit:lib/wrap > should return wrapped string 1`] = `
4+
"Parsed options can be accessed by calling [\`.opts<T>()\`](#commandoptst)
5+
on a [\`Command\`](#commandinfo) object, and are passed to the command's
6+
[\`action\`](#commandactionaction) handler.
7+
Multi-word options such as \`--template-engine\` are \`camelCased\`,
8+
becoming \`program.opts().templateEngine\`, or can be configured to be
9+
converted using \`snake_case\`, becoming \`program.opts().template_engine\`."
10+
`;

src/lib/__tests__/wrap.spec.mts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @file Unit Tests - wrap
3+
* @module string-wrap/lib/tests/unit/wrap
4+
*/
5+
6+
import parsedOptions from '#fixtures/parsed-options'
7+
import testSubject from '#lib/wrap'
8+
9+
describe('unit:lib/wrap', () => {
10+
it('should return wrapped string', () => {
11+
// Act
12+
const result = testSubject(parsedOptions, { columns: 72, hard: true })
13+
14+
// Expect
15+
expect(result).to.be.a('string').and.not.empty
16+
expect(result).toMatchSnapshot()
17+
})
18+
})

0 commit comments

Comments
 (0)