diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d9085..a4f4433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog +## Trunk + +* ts: move definition file into dist/pad.d.ts + ## Version 3.0.0 Backward incompatibility: diff --git a/lib/index.d.ts b/dist/pad.d.ts similarity index 100% rename from lib/index.d.ts rename to dist/pad.d.ts diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 927248f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -// Generated by CoffeeScript 2.4.1 -var pad; - -import * as wcwidth from 'wcwidth'; - -pad = function(text, length, options) { - var escapecolor, invert, padlength, textnocolors; - if (options == null) { - options = {}; - } - invert = typeof text === 'number'; - if (invert) { - [length, text] = [text, length]; - } - if (typeof options === 'string') { - options = { - char: options - }; - } - if (options.char == null) { - options.char = ' '; - } - if (options.strip == null) { - options.strip = false; - } - if (typeof text !== 'string') { - text = text.toString(); - } - textnocolors = null; - pad = ''; - if (options.colors) { - escapecolor = /\x1B\[(?:[0-9]{1,2}(?:;[0-9]{1,2})?)?[m|K]/g; - textnocolors = text.replace(escapecolor, ''); - } - padlength = options.fixed_width ? length - (textnocolors || text).length : length - wcwidth.config(options.wcwidth_options)(textnocolors || text); - if (padlength < 0) { - if (options.strip) { - if (invert) { - return text.substr(length * -1); - } else { - return text.substr(0, length); - } - } - return text; - } - pad += options.char.repeat(padlength); - if (invert) { - return pad + text; - } else { - return text + pad; - } -}; - -export default pad; diff --git a/package.json b/package.json index e3102ea..5d10ab5 100644 --- a/package.json +++ b/package.json @@ -44,12 +44,12 @@ "patch": "npm version patch -m 'Bump to version %s'", "minor": "npm version minor -m 'Bump to version %s'", "major": "npm version major -m 'Bump to version %s'", - "build": "coffee -b -o lib src && rollup -c", + "build": "coffee -b -o lib src && rollup -c && rm -r lib && cp -p src/index.d.ts dist/pad.d.ts", "pretest": "npm run build", "test": "mocha test/**/*.coffee" }, "dependencies": { "wcwidth": "^1.0.1" }, - "types": "lib/index.d.ts" + "types": "dist/pad.d.ts" } diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..213767a --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for pad 1.1 +// Project: https://github.com/wdavidw/node-pad#readme +// Definitions by: Mohamed Hegazy +// windware +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +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; +/** 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 namespace pad {}