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 #234

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
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import flatten from './flatten'
import snakeToCamel from './snake-to-camel'
import padLeft from './pad-left'

export {flatten, snakeToCamel, padLeft}

export {flatten, snakeToCamel}
21 changes: 21 additions & 0 deletions src/pad-left.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default padLeft

/**
* 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 padLeft(str, size, padWith) {
if (size <= str.length) {
return str
} else {
return Array(size - str.length + 1).join(padWith || '0') + str
}
}

20 changes: 20 additions & 0 deletions test/pad-left.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import test from 'ava'
import {padLeft} from '../src'

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

test('defaults to pad a zero', t => {
const original = '123'
const expected = '00123'
const padLength = 5
const actual = padLeft(original, padLength)
t.same(actual, expected)
})