From 7d1d7d909abbd23972b732ce4094715853adcb29 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 14 Mar 2016 22:17:46 -0700 Subject: [PATCH] Add fp padChars methods. --- fp/_mapping.js | 13 ++++++++++--- test/test-fp.js | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/fp/_mapping.js b/fp/_mapping.js index b69e2efb4..73440c917 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -72,9 +72,10 @@ exports.aryMethod = { 'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith', 'getOr', 'inRange', 'intersectionBy', 'intersectionWith', 'invokeArgs', 'isEqualWith', 'isMatchWith', 'flatMapDepth', 'mergeWith', 'orderBy', - 'pullAllBy', 'pullAllWith', 'reduce', 'reduceRight', 'replace', 'set', - 'slice', 'sortedIndexBy', 'sortedLastIndexBy', 'transform', 'unionBy', - 'unionWith', 'update', 'xorBy', 'xorWith', 'zipWith' + 'padChars', 'padCharsEnd', 'padCharsStart', 'pullAllBy', 'pullAllWith', + 'reduce', 'reduceRight', 'replace', 'set', 'slice', 'sortedIndexBy', + 'sortedLastIndexBy', 'transform', 'unionBy', 'unionWith', 'update', + 'xorBy', 'xorWith', 'zipWith' ], '4': [ 'fill', 'setWith', 'updateWith' @@ -143,6 +144,9 @@ exports.methodRearg = { 'invokeArgs': [1, 0, 2], 'isMatchWith': [2, 1, 0], 'mergeWith': [1, 2, 0], + 'padChars': [2, 1, 0], + 'padCharsEnd': [2, 1, 0], + 'padCharsStart': [2, 1, 0], 'pullAllBy': [2, 1, 0], 'pullAllWith': [2, 1, 0], 'setWith': [3, 1, 2, 0], @@ -223,6 +227,9 @@ exports.remap = { 'curryRightN': 'curryRight', 'getOr': 'get', 'invokeArgs': 'invoke', + 'padChars': 'pad', + 'padCharsEnd': 'padEnd', + 'padCharsStart': 'padStart', 'restFrom': 'rest', 'spreadFrom': 'spread', 'trimChars': 'trim', diff --git a/test/test-fp.js b/test/test-fp.js index 3e33190cb..84fa0b2bf 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1382,6 +1382,26 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('padChars methods'); + + _.each(['padChars', 'padCharsStart', 'padCharsEnd'], function(methodName) { + var func = fp[methodName], + isPad = methodName == 'padChars', + isStart = methodName == 'padCharsStart'; + + QUnit.test('`_.' + methodName + '` should truncate pad characters to fit the pad length', function(assert) { + assert.expect(1); + + if (isPad) { + assert.strictEqual(func('_-')(8)('abc'), '_-abc_-_'); + } else { + assert.strictEqual(func('_-')(6)('abc'), isStart ? '_-_abc' : 'abc_-_'); + } + }); + }); + + /*--------------------------------------------------------------------------*/ + QUnit.module('fp.partial and fp.partialRight'); _.each(['partial', 'partialRight'], function(methodName) { @@ -1546,7 +1566,7 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('fp.trimChars'); + QUnit.module('trimChars methods'); _.each(['trimChars', 'trimCharsStart', 'trimCharsEnd'], function(methodName, index) { var func = fp[methodName],