@@ -25,6 +25,8 @@ Wrap a string
2525 - [ ` lines(thing, config[, options]) ` ] ( #linesthing-config-options )
2626 - [ ` wrap(thing, config[, options]) ` ] ( #wrapthing-config-options )
2727- [ Types] ( #types )
28+ - [ ` ColumnsFunction<[T]> ` ] ( #columnsfunctiont )
29+ - [ ` Columns ` ] ( #columns )
2830 - [ ` Config ` ] ( #config )
2931 - [ ` LinesInfo ` ] ( #linesinfo )
3032 - [ ` Options ` ] ( #options )
@@ -41,6 +43,7 @@ This is a small, but useful package for word-wrapping a string to a specified co
4143### Features
4244
4345\: rainbow: [ ansi] [ ] support\
46+ \: triangular\_ ruler: configure columns dynamically\
4447\: unicorn: emoji and fullwidth character support\
4548\: arrow\_ right: indent and pad lines
4649
@@ -133,15 +136,16 @@ Get info about the lines of a wrapped string.
133136
134137#### Overloads
135138
136- - ` lines(thing: unknown, config: number | string , options?: Options | null | undefined): LinesInfo `
137- - ` lines(thing: unknown, config: Config | number | string ): LinesInfo `
139+ - ` lines(thing: unknown, config: Columns , options?: Options | null | undefined): LinesInfo `
140+ - ` lines(thing: unknown, config: Columns | Config ): LinesInfo `
138141
139142##### Parameters
140143
141144- ` thing ` (` unknown ` )
142145 — the thing to wrap. non-string values will be converted to strings
143- - ` config ` ([ ` Config ` ] ( #config ) | ` number ` | ` string ` )
144- — the wrap configuration or the number of columns to wrap the string to
146+ - ` config ` ([ ` Columns ` ] ( #columns ) | [ ` Config ` ] ( #config ) )
147+ — the wrap configuration, the number of columns to wrap the string to,
148+ or a function that returns the maximum number of columns per line
145149- ` options ` ([ ` Options ` ] ( #options ) | ` null ` | ` undefined ` , ` optional ` )
146150 — options for wrapping
147151
@@ -155,15 +159,16 @@ Wrap a string to the specified column width.
155159
156160#### Overloads
157161
158- - ` wrap(thing: unknown, config: number | string , options?: Options | null | undefined): string `
159- - ` wrap(thing: unknown, config: Config | number | string ): string `
162+ - ` wrap(thing: unknown, config: Columns , options?: Options | null | undefined): string `
163+ - ` wrap(thing: unknown, config: Columns | Config ): string `
160164
161165##### Parameters
162166
163167- ` thing ` (` unknown ` )
164168 — the thing to wrap. non-string values will be converted to strings
165- - ` config ` ([ ` Config ` ] ( #config ) | ` number ` | ` string ` )
166- — the wrap configuration or the number of columns to wrap the string to
169+ - ` config ` ([ ` Columns ` ] ( #columns ) | [ ` Config ` ] ( #config ) )
170+ — the wrap configuration, the number of columns to wrap the string to,
171+ or a function that returns the maximum number of columns per line
167172- ` options ` ([ ` Options ` ] ( #options ) | ` null ` | ` undefined ` , ` optional ` )
168173 — options for wrapping
169174
@@ -175,6 +180,45 @@ Wrap a string to the specified column width.
175180
176181This package is fully typed with [ TypeScript] [ ] .
177182
183+ ### ` ColumnsFunction<[T]> `
184+
185+ Get the maximum number of columns for the line at ` index ` (` type ` ).
186+
187+ > 👉 ** Note** : The total number of available columns is calculated from the
188+ > maximum number of columns, indentation, and padding.
189+
190+ ``` ts
191+ type ColumnsFunction <T extends number | string = number | string > = (
192+ this : void ,
193+ index : number ,
194+ lines ? : readonly string [] | null | undefined
195+ ) => T
196+ ` ` `
197+
198+ #### Type Parameters
199+
200+ - ` T ` ( ` number ` | ` string ` , optional)
201+ — the maximum number of columns
202+
203+ #### Parameters
204+
205+ - ` index ` ( ` number ` )
206+ — the index of the current line, or ` -1 ` on init
207+ - ` lines ` ( ` readonly string []` | ` null ` | ` undefined ` , optional)
208+ — the current list of lines
209+
210+ #### Returns
211+
212+ ( ` T ` ) The maximum number of columns
213+
214+ ### ` Columns `
215+
216+ Union of column configurations ( ` type ` ).
217+
218+ ` ` ` ts
219+ type Columns = ColumnsFunction | number | string
220+ ` ` `
221+
178222### ` Config `
179223
180224String wrapping configuration ( ` interface ` ).
@@ -185,15 +229,17 @@ String wrapping configuration (`interface`).
185229
186230#### Properties
187231
188- - ` columns ` (` number ` | ` string ` )
189- — the number of columns to wrap the string to
232+ - ` columns ` ([ ` Columns ` ](#columns) )
233+ — the number of columns to wrap the string to, or a function that returns the maximum number of columns per line
190234
191235### ` LinesInfo `
192236
193237Info about the lines of a wrapped string ( ` interface ` ).
194238
195239#### Properties
196240
241+ - ` columns ` ([ ` ColumnsFunction <number >` ](#columnsfunctiont))
242+ — get the maximum number of columns per line
197243- ` eol ` ( ` string ` )
198244 — the character, or characters, used to mark the end of a line
199245- ` indent ` ([ ` SpacerFunction <string >` ](#spacerfunctiont))
@@ -270,7 +316,7 @@ type SpacerFunction<
270316#### Parameters
271317
272318- ` index ` ( ` number ` )
273- — the index of the current line
319+ — the index of the current line, or ` - 1 ` on init
274320- ` lines ` ( ` readonly string []` | ` null ` | ` undefined ` , optional)
275321 — the current list of lines
276322
0 commit comments