es-string-algorithm
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -5,3 +5,3 @@ /** | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -19,3 +19,3 @@ * @param target search target string | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -33,3 +33,3 @@ * @param target search target string | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`!k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`!k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -47,3 +47,3 @@ * @param target search target string | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -50,0 +50,0 @@ * @param target search target string |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const findFirst = (target, key, pos, pred, n) => { | ||
const k = typeof n !== 'undefined' ? key.substring(0, n) : key; | ||
const includes = (target, searchString, n) => { | ||
if (typeof n !== 'number') | ||
return target.includes(searchString); | ||
let i = 0; | ||
for (const t of target) { | ||
if (pos <= i && pred(t, k)) | ||
if (n <= i) | ||
break; | ||
if (t === searchString) | ||
return true; | ||
++i; | ||
} | ||
return false; | ||
}; | ||
const findFirst = (target, pos, pred) => { | ||
let i = 0; | ||
for (const t of target) { | ||
if (pos <= i && pred(t)) | ||
return i; | ||
@@ -17,3 +29,3 @@ ++i; | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -26,4 +38,4 @@ * @param target search target string | ||
*/ | ||
exports.findFirstOf = (target, key, pos = 0, n) => findFirst(target, key, pos, (c, k) => k.includes(c), n); | ||
const findLast = (target, key, pos, pred, n) => { | ||
exports.findFirstOf = (target, key, pos = 0, n) => findFirst(target, pos, t => includes(key, t, n)); | ||
const findLast = (target, pos, pred) => { | ||
const targetArr = Array.from(target); | ||
@@ -33,3 +45,3 @@ // if (targetArr.length <= pos) return -1; | ||
pos = -1 === pos || targetArr.length <= pos ? 0 : targetArr.length - 1 - pos; | ||
const re = findFirst(targetArr, key, pos, pred, n); | ||
const re = findFirst(targetArr, pos, pred); | ||
return -1 === re ? -1 : targetArr.length - 1 - re; | ||
@@ -41,3 +53,3 @@ }; | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -50,3 +62,3 @@ * @param target search target string | ||
*/ | ||
exports.findLastof = (target, key, pos = -1, n) => findLast(target, key, pos, (c, k) => k.includes(c), n); | ||
exports.findLastof = (target, key, pos = -1, n) => findLast(target, pos, t => includes(key, t, n)); | ||
/** | ||
@@ -56,3 +68,3 @@ * Determines the lowest position `xpos`, if possible, such that both of the following conditions hold: | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`!k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`!k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -65,3 +77,3 @@ * @param target search target string | ||
*/ | ||
exports.findFirstNotOf = (target, key, pos = 0, n) => findFirst(target, key, pos, (c, k) => !k.includes(c), n); | ||
exports.findFirstNotOf = (target, key, pos = 0, n) => findFirst(target, pos, t => !includes(key, t, n)); | ||
/** | ||
@@ -71,3 +83,3 @@ * Determines the highest position `xpos`, if possible, such that both of the following conditions hold: | ||
* 1. `pos <= xpos` and `xpos < size(target)` | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to [`key.substring(0, n)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)) | ||
* 2. [`k.includes(at(target, xpos))`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) (When `n` is `undefined` (omitted), `k` is equal to `key`. Otherwise, `k` is equal to `std.substr(key, 0, n)`) | ||
* | ||
@@ -80,2 +92,2 @@ * @param target search target string | ||
*/ | ||
exports.findLastNotof = (target, key, pos = -1, n) => findLast(target, key, pos, (c, k) => !k.includes(c), n); | ||
exports.findLastNotof = (target, key, pos = -1, n) => findLast(target, pos, t => !includes(key, t, n)); |
{ | ||
"name": "es-string-algorithm", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "port from C++STL std::basic_string", | ||
@@ -27,9 +27,9 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/jest": "^24.0.0", | ||
"jest": "^23.6.0", | ||
"prettier": "^1.16.4", | ||
"ts-jest": "^23.10.5", | ||
"tslint": "^5.12.1", | ||
"@types/jest": "^24.0.13", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.17.1", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "^5.17.0", | ||
"tslint-plugin-prettier": "^2.0.1", | ||
"typescript": "^3.3.3" | ||
"typescript": "^3.5.1" | ||
}, | ||
@@ -36,0 +36,0 @@ "jest": { |
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
156
15937