Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

WIP: Cannot get coverage quite there #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default flatten
* @return {Array} - The flattened array
*/
function flatten(...args) {
return args.reduce(function flattenReducer(flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(...toFlatten) : toFlatten)
}, [])
}
return args.reduce(function flattenReducer(flat, toFlatten) {

return flat.concat(Array.isArray(toFlatten) ? flatten(...toFlatten) : toFlatten)
}, [])
}
55 changes: 28 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import reduce from './reduce-to-tally'
import flatten from './flatten'
import getQueryStringParam from './get-query-string-param'
import snakeToCamel from './snake-to-camel'
import padLeft from './pad-left'
import padRight from './pad-right'
import randomInteger from './random-integer'
import arrayFill from './array-fill'
import sortObjectsArray from './sort-objects-array'
Expand All @@ -26,29 +26,30 @@ import dec2bin from './dec2bin'
import searchAndReplace from './search-and-replace'

export {
reduce,
flatten,
snakeToCamel,
getQueryStringParam,
padLeft,
randomInteger,
arrayFill,
sortObjectsArray,
objectValuesToString,
getObjectSize,
isArray,
validateEmail,
hex2rgb,
isNullOrWhitespace,
isToday,
startsWith,
removeDuplicates,
add,
subtract,
divide,
multiply,
square,
sum,
dec2bin,
searchAndReplace,
}
reduce,
flatten,
snakeToCamel,
getQueryStringParam,
padLeft,
padRight,
randomInteger,
arrayFill,
sortObjectsArray,
objectValuesToString,
getObjectSize,
isArray,
validateEmail,
hex2rgb,
isNullOrWhitespace,
isToday,
startsWith,
removeDuplicates,
add,
subtract,
divide,
multiply,
square,
sum,
dec2bin,
searchAndReplace,
}
20 changes: 20 additions & 0 deletions src/pad-right.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default padRight

/**
* Original Source: http://stackoverflow.com/a/34083277/971592
*
* This method will pad the left of the given string by
* the given size with the given character
*
* @param {String} str - The string to pad
* @param {Number} size - The total size to pad
* @param {String} padWith - The character to use for padding
* @return {String} - The padded string
*/
function padRight(str, size, padWith) {
if (size <= str.length) {
return str
} else {
return str + Array(size - str.length + 1).join(padWith || '0')
}
}
27 changes: 27 additions & 0 deletions test/pad-right.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import test from 'ava'
import { padRight } from '../src'

test('pads left of the given string', t => {
const original = '123'
const expected = '123zz'
const padLength = 5
const padWith = 'z'
const actual = padRight(original, padLength, padWith)
t.deepEqual(actual, expected)
})

test('defaults to pad a zero', t => {
const original = '123'
const expected = '12300'
const padLength = 5
const actual = padRight(original, padLength)
t.deepEqual(actual, expected)
})

test('does not pad a string longer than the pad length', t => {
const original = '1234'
const expected = '1234'
const padLength = 3
const actual = padRight(original, padLength)
t.deepEqual(actual, expected)
})