@oozcitak/util
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -43,2 +43,9 @@ /** | ||
/** | ||
* Returns the substring including the current character without changing | ||
* the current position. Returns character points instead of code points. | ||
* | ||
* @param charCount - the number of character codes to return | ||
*/ | ||
peekChar(charCount?: number): string; | ||
/** | ||
* Determines whether the substring including the current character | ||
@@ -55,2 +62,6 @@ * starts with the given string. | ||
/** | ||
* Moves to the next character code. | ||
*/ | ||
nextChar(): boolean; | ||
/** | ||
* Moves to the previous code point. | ||
@@ -60,2 +71,6 @@ */ | ||
/** | ||
* Moves to the previous character code. | ||
*/ | ||
prevChar(): boolean; | ||
/** | ||
* Seeks a number of code points relative to the current position. | ||
@@ -68,2 +83,9 @@ * | ||
/** | ||
* Seeks a number of character codes relative to the current position. | ||
* | ||
* @param charCount - the number of character codes to return | ||
* @param reference - reference of the seek operation | ||
*/ | ||
seekChar(charCount: number, reference?: SeekOrigin): void; | ||
/** | ||
* Consumes a number of code points. | ||
@@ -75,2 +97,8 @@ * | ||
/** | ||
* Consumes a number of character codes. | ||
* | ||
* @param countOrFunc - the number of character codes to take | ||
*/ | ||
takeChar(countOrFunc: number | ((char: string) => boolean)): string; | ||
/** | ||
* Skips a number of code points. | ||
@@ -82,13 +110,7 @@ * | ||
/** | ||
* Sets the start index to the current position for the `getMarked` function. | ||
* Skips a number of character codes. | ||
* | ||
* @param countOrFunc - the number of character codes to skip | ||
*/ | ||
markStart(): void; | ||
/** | ||
* Sets the end index to the current position for the `getMarked` function. | ||
*/ | ||
markEnd(): void; | ||
/** | ||
* Gets the string between start and marks. | ||
*/ | ||
getMarked(): string; | ||
skipChar(countOrFunc: number | ((char: string) => boolean)): void; | ||
} | ||
@@ -95,0 +117,0 @@ /** |
@@ -91,2 +91,15 @@ "use strict"; | ||
/** | ||
* Returns the substring including the current character without changing | ||
* the current position. Returns character points instead of code points. | ||
* | ||
* @param charCount - the number of character codes to return | ||
*/ | ||
peekChar(charCount) { | ||
if (this.eof) | ||
return ""; | ||
if (charCount === undefined) | ||
return this._chars.slice(this._index); | ||
return this._chars.slice(this._index, this._index + charCount); | ||
} | ||
/** | ||
* Determines whether the substring including the current character | ||
@@ -132,2 +145,17 @@ * starts with the given string. | ||
/** | ||
* Moves to the next character code. | ||
*/ | ||
nextChar() { | ||
if (this.eof) | ||
return false; | ||
this._codePoint = undefined; | ||
this._c = undefined; | ||
this._index++; | ||
this._first = this._index < this._length ? this._chars.charCodeAt(this._index) : -1; | ||
this._second = this._index < this._length - 1 ? this._chars.charCodeAt(this._index + 1) : -1; | ||
this._isSurrogatePair = (this._first >= 0xD800 && this._first <= 0xDBFF && | ||
this._second >= 0xDC00 && this._second <= 0xDFFF); | ||
return true; | ||
} | ||
/** | ||
* Moves to the previous code point. | ||
@@ -150,2 +178,17 @@ */ | ||
/** | ||
* Moves to the previous character code. | ||
*/ | ||
prevChar() { | ||
if (this._index === 0) | ||
return false; | ||
this._codePoint = undefined; | ||
this._c = undefined; | ||
this._index--; | ||
this._first = this._index < this._length ? this._chars.charCodeAt(this._index) : -1; | ||
this._second = this._index < this._length - 1 ? this._chars.charCodeAt(this._index + 1) : -1; | ||
this._isSurrogatePair = (this._first >= 0xD800 && this._first <= 0xDBFF && | ||
this._second >= 0xDC00 && this._second <= 0xDFFF); | ||
return true; | ||
} | ||
/** | ||
* Seeks a number of code points relative to the current position. | ||
@@ -190,2 +233,29 @@ * | ||
/** | ||
* Seeks a number of character codes relative to the current position. | ||
* | ||
* @param charCount - the number of character codes to return | ||
* @param reference - reference of the seek operation | ||
*/ | ||
seekChar(charCount, reference = SeekOrigin.Current) { | ||
this._codePoint = undefined; | ||
this._c = undefined; | ||
if (reference === SeekOrigin.Start) { | ||
this._index = charCount; | ||
} | ||
else if (reference === SeekOrigin.End) { | ||
this._index = this._length - charCount; | ||
} | ||
else { | ||
this._index += charCount; | ||
} | ||
if (this._index < 0) | ||
this._index = 0; | ||
if (this._index > this._length) | ||
this._index = this._length; | ||
this._first = this._index < this._length ? this._chars.charCodeAt(this._index) : -1; | ||
this._second = this._index < this._length - 1 ? this._chars.charCodeAt(this._index + 1) : -1; | ||
this._isSurrogatePair = (this._first >= 0xD800 && this._first <= 0xDBFF && | ||
this._second >= 0xDC00 && this._second <= 0xDFFF); | ||
} | ||
/** | ||
* Consumes a number of code points. | ||
@@ -219,2 +289,23 @@ * | ||
/** | ||
* Consumes a number of character codes. | ||
* | ||
* @param countOrFunc - the number of character codes to take | ||
*/ | ||
takeChar(countOrFunc) { | ||
if (_1.isNumber(countOrFunc)) { | ||
if (countOrFunc === 0) | ||
return ""; | ||
const str = this._chars.slice(this._index, this._index + countOrFunc); | ||
this.seekChar(countOrFunc); | ||
return str; | ||
} | ||
else { | ||
if (!countOrFunc(this.c)) | ||
return ""; | ||
const startIndex = this._index; | ||
while (this.nextChar() && countOrFunc(this.c)) { } | ||
return this._chars.slice(startIndex, this._index); | ||
} | ||
} | ||
/** | ||
* Skips a number of code points. | ||
@@ -240,20 +331,18 @@ * | ||
/** | ||
* Sets the start index to the current position for the `getMarked` function. | ||
* Skips a number of character codes. | ||
* | ||
* @param countOrFunc - the number of character codes to skip | ||
*/ | ||
markStart() { | ||
this._startMark = this._index; | ||
this._endMark = this._index; | ||
skipChar(countOrFunc) { | ||
if (_1.isNumber(countOrFunc)) { | ||
if (countOrFunc === 0) | ||
return; | ||
this.seekChar(countOrFunc); | ||
} | ||
else { | ||
if (!countOrFunc(this.c)) | ||
return; | ||
while (this.nextChar() && countOrFunc(this.c)) { } | ||
} | ||
} | ||
/** | ||
* Sets the end index to the current position for the `getMarked` function. | ||
*/ | ||
markEnd() { | ||
this._endMark = this._index; | ||
} | ||
/** | ||
* Gets the string between start and marks. | ||
*/ | ||
getMarked() { | ||
return this._chars.slice(this._startMark, this._endMark); | ||
} | ||
} | ||
@@ -260,0 +349,0 @@ exports.StringWalker = StringWalker; |
{ | ||
"name": "@oozcitak/util", | ||
"version": "3.1.0", | ||
"version": "4.0.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
69624
1491