diff --git a/CHANGELOG.md b/CHANGELOG.md index 1847ab9..f3fea86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog +## Trunk + +* ts: api tests +* src: rewrite in js + ## Version 3.2.0 * package: fix rollup dev dependencies diff --git a/dist/pad.cjs.js b/dist/pad.cjs.js index 5e53de2..46526bd 100644 --- a/dist/pad.cjs.js +++ b/dist/pad.cjs.js @@ -314,7 +314,7 @@ var lib = function lib(text, length) { textnocolors = text.replace(escapecolor, ''); } - padlength = options.fixed_width ? length - (textnocolors || text).length : length - wcwidth_1.config(options.wcwidth_options)(textnocolors || text); + padlength = options.fixed_width === true ? length - (textnocolors || text).length : length - wcwidth_1.config(options.wcwidth_options)(textnocolors || text); if (padlength < 0) { if (options.strip) { diff --git a/dist/pad.d.ts b/dist/pad.d.ts index 213767a..914744a 100644 --- a/dist/pad.d.ts +++ b/dist/pad.d.ts @@ -9,10 +9,39 @@ export = pad; /** Left pad */ declare function pad(length: number, text: string, char?: string): string; // tslint:disable-next-line unified-signatures -declare function pad(length: number, text: string, options?: { char?: string, colors?: boolean, strip?: boolean }): string; +declare function pad(length: number, text: string, options?: pad.Options): string; /** Right pad */ declare function pad(text: string, length: number, char?: string): string; // tslint:disable-next-line unified-signatures -declare function pad(text: string, length: number, options?: { char?: string, colors?: boolean, strip?: boolean }): string; +declare function pad(text: string, length: number, options?: pad.Options): string; -declare namespace pad {} +declare namespace pad { + + interface WCWidthOptions { + control?: number + nul?: number + } + + interface Options { + /** + * The character used to fill the gap. + */ + char?: string + /** + * Adjust to hidden terminal color characters. + */ + colors?: boolean + /** + * Remove characters from text if length smaller than text length, default to "false". + */ + strip?: boolean + /** + * An optimization option to disable the usage of the wcwidth package to handle the discovery of characters using more than one column for display. + */ + fixed_width?: boolean + /** + * Options passed to the wcwidth package used to calculate the display width of characters using more than one column. + */ + wcwidth_options?: pad.WCWidthOptions + } +} diff --git a/dist/pad.esm.js b/dist/pad.esm.js index 25b81e1..f77698f 100644 --- a/dist/pad.esm.js +++ b/dist/pad.esm.js @@ -312,7 +312,7 @@ var lib = function lib(text, length) { textnocolors = text.replace(escapecolor, ''); } - padlength = options.fixed_width ? length - (textnocolors || text).length : length - wcwidth_1.config(options.wcwidth_options)(textnocolors || text); + padlength = options.fixed_width === true ? length - (textnocolors || text).length : length - wcwidth_1.config(options.wcwidth_options)(textnocolors || text); if (padlength < 0) { if (options.strip) { diff --git a/dist/pad.umd.js b/dist/pad.umd.js index 9a9470b..6651909 100644 --- a/dist/pad.umd.js +++ b/dist/pad.umd.js @@ -318,7 +318,7 @@ textnocolors = text.replace(escapecolor, ''); } - padlength = options.fixed_width ? length - (textnocolors || text).length : length - wcwidth_1.config(options.wcwidth_options)(textnocolors || text); + padlength = options.fixed_width === true ? length - (textnocolors || text).length : length - wcwidth_1.config(options.wcwidth_options)(textnocolors || text); if (padlength < 0) { if (options.strip) { diff --git a/test/api.types.ts b/test/api.types.ts index 719cc60..2f6b059 100644 --- a/test/api.types.ts +++ b/test/api.types.ts @@ -8,8 +8,8 @@ describe('API Types', () => { it('Arguments', () => { pad('text', 5).should.eql('text ') pad('text', 5, {}).should.eql('text ') - pad(5, 'text').should.eql('text ') - pad(5, 'text', {}).should.eql('text ') + pad(5, 'text').should.eql(' text') + pad(5, 'text', {}).should.eql(' text') }) it('Options', () => {