-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strings): add charRange(), add radix & zero-pad presets
- Loading branch information
1 parent
ae1ec8d
commit c9e5a63
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Yields iterator of characters [`from`..`to`] (inclusive). Uses | ||
* reverse ordering if `to` < `from`. | ||
* | ||
* @param from | ||
* @param to | ||
*/ | ||
export function* charRange(from: string | number, to: string | number) { | ||
let i = typeof from === "string" ? from.charCodeAt(0) : from; | ||
const end = typeof to === "string" ? to.charCodeAt(0) : to; | ||
if (i <= end) { | ||
for (; i <= end; i++) { | ||
yield String.fromCharCode(i); | ||
} | ||
} else { | ||
for (; i >= end; i--) { | ||
yield String.fromCharCode(i); | ||
} | ||
} | ||
} |