Skip to content

Commit

Permalink
ts: api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 22, 2019
1 parent 4c4a13a commit e35bb3a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

# Changelog

## Trunk

* ts: api tests
* src: rewrite in js

## Version 3.2.0

* package: fix rollup dev dependencies
Expand Down
2 changes: 1 addition & 1 deletion dist/pad.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 32 additions & 3 deletions dist/pad.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion dist/pad.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion dist/pad.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit e35bb3a

Please sign in to comment.