Comparing version 0.24.0 to 0.25.0
@@ -493,2 +493,36 @@ 'use strict'; | ||
/** | ||
* Includes determines whether one string can be found in another string | ||
* | ||
* @param {string} string input string | ||
* @param {string} substr candidate string to be searched for | ||
* @param {Number} start optional index to begin search for string | ||
* @returns {boolean} does the input string include the substring? | ||
* | ||
* @example | ||
* const result = strings.includes('This Lovely Life', 'Love'); | ||
* console.log(result); | ||
* > true | ||
* @example | ||
* const result = strings.includes('This Lovely Life', 'Love', 5); | ||
* console.log(result); | ||
* > false | ||
*/ | ||
function includes (string, substr, start = 0) { | ||
if (string.length === 0) return false; | ||
const len = substr.length; | ||
const first = substr.charAt(0); | ||
if (start === 0 && string.substring(0, len) === substr) return true; | ||
return string.split('').reduce((res, cur, i) => { | ||
if (i >= start) { | ||
if (res) return res; | ||
if (cur === first) { | ||
return string.substring(i, i + len) === substr; | ||
} | ||
} | ||
return false; | ||
}, false); | ||
} | ||
/** | ||
* Pads the end of a string w/ repeated spaces|substrings | ||
@@ -643,2 +677,3 @@ * | ||
endsWith: endsWith, | ||
includes: includes, | ||
padEnd: padEnd, | ||
@@ -645,0 +680,0 @@ padStart: padStart, |
@@ -489,2 +489,36 @@ /** | ||
/** | ||
* Includes determines whether one string can be found in another string | ||
* | ||
* @param {string} string input string | ||
* @param {string} substr candidate string to be searched for | ||
* @param {Number} start optional index to begin search for string | ||
* @returns {boolean} does the input string include the substring? | ||
* | ||
* @example | ||
* const result = strings.includes('This Lovely Life', 'Love'); | ||
* console.log(result); | ||
* > true | ||
* @example | ||
* const result = strings.includes('This Lovely Life', 'Love', 5); | ||
* console.log(result); | ||
* > false | ||
*/ | ||
function includes (string, substr, start = 0) { | ||
if (string.length === 0) return false; | ||
const len = substr.length; | ||
const first = substr.charAt(0); | ||
if (start === 0 && string.substring(0, len) === substr) return true; | ||
return string.split('').reduce((res, cur, i) => { | ||
if (i >= start) { | ||
if (res) return res; | ||
if (cur === first) { | ||
return string.substring(i, i + len) === substr; | ||
} | ||
} | ||
return false; | ||
}, false); | ||
} | ||
/** | ||
* Pads the end of a string w/ repeated spaces|substrings | ||
@@ -639,2 +673,3 @@ * | ||
endsWith: endsWith, | ||
includes: includes, | ||
padEnd: padEnd, | ||
@@ -641,0 +676,0 @@ padStart: padStart, |
{ | ||
"name": "absurdum", | ||
"version": "0.24.0", | ||
"version": "0.25.0", | ||
"description": "Reductio Ad Absurdum - The Ridiculous Application of Reduce", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"preversion": "npm test && npm run lint && npm run types", | ||
"version": "npm run clean && npm run build && sleep 15 && git add dist/* && git diff --quiet && git diff --staged --quiet || git commit -am 'Build'", | ||
"version": "npm run build && git add dist/* && git diff --quiet && git diff --staged --quiet || git commit -am 'Build'", | ||
"postversion": "git push --follow-tags" | ||
@@ -38,0 +38,0 @@ }, |
@@ -90,2 +90,3 @@ [![GitHub release](https://img.shields.io/github/release/vanillaes/absurdum.svg)](https://github.com/vanillaes/absurdum/releases) | ||
- [endsWith][strings.endswith] | ||
- [includes][strings.includes] | ||
- [padEnd][strings.padEnd] | ||
@@ -97,2 +98,3 @@ - [padStart][strings.padStart] | ||
[strings.endswith]: ./docs/strings/endsWith.md | ||
[strings.includes]: ./docs/strings/includes.md | ||
[strings.padEnd]: ./docs/strings/padEnd.md | ||
@@ -99,0 +101,0 @@ [strings.padStart]: ./docs/strings/padStart.md |
export { endsWith } from "./endsWith.js"; | ||
export { includes } from "./includes.js"; | ||
export { padEnd } from "./padEnd.js"; | ||
@@ -3,0 +4,0 @@ export { padStart } from "./padStart.js"; |
export { endsWith } from './endsWith.js'; | ||
export { includes } from './includes.js'; | ||
export { padEnd } from './padEnd.js'; | ||
@@ -3,0 +4,0 @@ export { padStart } from './padStart.js'; |
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
88766
79
2309
110