Comparing version 1.1.1 to 1.1.2
38
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
const getStdin = require('get-stdin'); | ||
const meow = require('meow'); | ||
const lpadAlign = require('.'); | ||
var getStdin = require('get-stdin'); | ||
var meow = require('meow'); | ||
var lpadAlign = require('./'); | ||
const cli = meow(` | ||
Usage | ||
$ cat <file> | lpad-align | ||
Example | ||
$ cat unicorn.txt | lpad-align | ||
foo | ||
foobar | ||
foobarcat | ||
`, { | ||
var cli = meow({ | ||
help: [ | ||
'Usage', | ||
' $ cat <file> | lpad-align', | ||
'', | ||
'Example', | ||
' $ cat unicorn.txt | lpad-align', | ||
' foo', | ||
' foobar', | ||
' foobarcat' | ||
] | ||
}, { | ||
default: { | ||
@@ -22,8 +24,8 @@ indent: 4 | ||
getStdin().then(data => { | ||
const arr = data.split(/\r?\n/); | ||
getStdin(function (data) { | ||
var arr = data.split(/\r?\n/); | ||
for (const x of arr) { | ||
console.log(lpadAlign(x, arr, cli.flags.indent)); | ||
} | ||
arr.forEach(function (el) { | ||
console.log(lpadAlign(el, arr, cli.flags.indent)); | ||
}); | ||
}); |
14
index.js
'use strict'; | ||
const indentString = require('indent-string'); | ||
const longest = require('longest'); | ||
var indentString = require('indent-string'); | ||
var longest = require('longest'); | ||
module.exports = (str, arr, indent) => { | ||
const pad = typeof indent === 'number' ? indent : 0; | ||
module.exports = function (str, arr, indent) { | ||
var pad = typeof indent === 'number' ? indent : 0; | ||
if (typeof str !== 'string') { | ||
throw new TypeError(`Expected a \`string\`, got \`${typeof str}\``); | ||
throw new TypeError('Expected a `string`, got `' + typeof str + '`'); | ||
} | ||
if (!Array.isArray(arr)) { | ||
throw new TypeError(`Expected an \`Array\`, got \`${typeof arr}\``); | ||
throw new TypeError('Expected an `Array`, got `' + typeof arr + '`'); | ||
} | ||
return indentString(str, pad + longest(arr).length - str.length); | ||
return indentString(str, ' ', pad + longest(arr).length - str.length); | ||
}; |
{ | ||
"name": "lpad-align", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Left pad a string to align with the longest string in an array", | ||
@@ -14,3 +14,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=0.10.0" | ||
}, | ||
@@ -30,6 +30,5 @@ "scripts": { | ||
"dependencies": { | ||
"get-stdin": "^5.0.1", | ||
"indent-string": "^3.0.0", | ||
"longest": "^2.0.0", | ||
"lpad": "^2.0.1", | ||
"get-stdin": "^4.0.1", | ||
"indent-string": "^2.1.0", | ||
"longest": "^1.0.0", | ||
"meow": "^3.3.0" | ||
@@ -36,0 +35,0 @@ }, |
3766
4
40
+ Addedlongest@1.0.1(transitive)
- Removedlpad@^2.0.1
- Removedget-stdin@5.0.1(transitive)
- Removedindent-string@3.2.0(transitive)
- Removedlongest@2.0.1(transitive)
- Removedlpad@2.0.1(transitive)
Updatedget-stdin@^4.0.1
Updatedindent-string@^2.1.0
Updatedlongest@^1.0.0