Comparing version 0.15.0 to 0.15.1
{ | ||
"name": "absurdum", | ||
"version": "0.15.0", | ||
"version": "0.15.1", | ||
"description": "Reducio Ad Absurdum - The Riduculous Application of Reduce", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
export const endsWith = (string, substr) => { | ||
export const endsWith = (string, substr = '') => { | ||
return string.split('').reduce((acc, curr, idx, arr) => { | ||
@@ -6,2 +6,3 @@ // exit early on mismatch | ||
arr = arr.splice(0); | ||
return false; | ||
} | ||
@@ -14,3 +15,3 @@ // exit early on match | ||
return acc; | ||
}, false); | ||
}, null); | ||
}; |
@@ -23,1 +23,21 @@ import test from 'tape'; | ||
}); | ||
test(`strings.endsWith(string, substr) - returns falsy when the string doesn't end with the substr`, t => { | ||
const expect = false; | ||
const result = strings.endsWith('abc', 'f'); | ||
t.equal(Object.prototype.toString.call(result), '[object Boolean]', 'return type'); | ||
t.equal(result, expect, 'output value'); | ||
t.end(); | ||
}); | ||
test(`strings.endsWith(string, substr) - should not mutate the input`, t => { | ||
const input = 'abc'; | ||
const expect = 'abc'; | ||
strings.endsWith(input, 'f'); | ||
t.equal(input, expect, 'input mutation'); | ||
t.end(); | ||
}); |
export const startsWith = (string, substr) => { | ||
return string.split('').reduce((acc, curr, idx, arr) => { | ||
let chars = string.split(''); | ||
return chars.reduce((acc, curr, idx, arr) => { | ||
// exit early on mismatch | ||
if (curr !== substr[idx]) { | ||
arr = arr.splice(0); | ||
chars = arr.splice(0); | ||
return false; | ||
} | ||
// exit early on match | ||
if (idx === substr.length - 1) { | ||
arr = arr.splice(0); | ||
chars = arr.splice(0); | ||
return true; | ||
} | ||
return acc; | ||
}, false); | ||
}, null); | ||
}; |
@@ -23,1 +23,21 @@ import test from 'tape'; | ||
}); | ||
test(`strings.startsWith(string, substr) - returns falsy when the string doesn't start with the substr`, t => { | ||
const expect = false; | ||
const result = strings.startsWith('abc', 'f'); | ||
t.equal(Object.prototype.toString.call(result), '[object Boolean]', 'return type'); | ||
t.equal(result, expect, 'output value'); | ||
t.end(); | ||
}); | ||
test(`strings.startsWith(string, substr) - should not mutate the input`, t => { | ||
const input = 'abc'; | ||
const expect = 'abc'; | ||
strings.startsWith(input, 'f'); | ||
t.equal(input, expect, 'input mutation'); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22972
423