@oozcitak/util
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -62,2 +62,14 @@ /** | ||
seek(count: number, reference?: SeekOrigin): void; | ||
/** | ||
* Consumes a number of code points. | ||
* | ||
* @param count - number of code points to take | ||
*/ | ||
take(countOrFunc: number | ((char: string) => boolean)): string; | ||
/** | ||
* Skips a number of code points. | ||
* | ||
* @param count - number of code points to skip | ||
*/ | ||
skip(countOrFunc: number | ((char: string) => boolean)): void; | ||
} | ||
@@ -64,0 +76,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _1 = require("."); | ||
/** | ||
@@ -183,2 +184,50 @@ * Walks the code points of a string. | ||
} | ||
/** | ||
* Consumes a number of code points. | ||
* | ||
* @param count - number of code points to take | ||
*/ | ||
take(countOrFunc) { | ||
if (_1.isNumber(countOrFunc)) { | ||
if (countOrFunc === 0) | ||
return ""; | ||
let str = ""; | ||
let n = 0; | ||
while (n < countOrFunc) { | ||
str += this.c; | ||
this.next(); | ||
n++; | ||
} | ||
return str; | ||
} | ||
else { | ||
if (!countOrFunc(this.c)) | ||
return ""; | ||
let str = this.c; | ||
while (this.next() && countOrFunc(this.c)) { | ||
str += this.c; | ||
} | ||
return str; | ||
} | ||
} | ||
/** | ||
* Skips a number of code points. | ||
* | ||
* @param count - number of code points to skip | ||
*/ | ||
skip(countOrFunc) { | ||
if (_1.isNumber(countOrFunc)) { | ||
if (countOrFunc === 0) | ||
return; | ||
let n = 0; | ||
while (n < countOrFunc && this.next()) { | ||
n++; | ||
} | ||
} | ||
else { | ||
if (!countOrFunc(this.c)) | ||
return; | ||
while (this.next() && countOrFunc(this.c)) { } | ||
} | ||
} | ||
} | ||
@@ -185,0 +234,0 @@ exports.StringWalker = StringWalker; |
{ | ||
"name": "@oozcitak/util", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "util", |
Sorry, the diff of this file is not supported yet
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
53071
1120