forked from thi-ng/umbrella
-
Notifications
You must be signed in to change notification settings - Fork 0
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 hstr() (hollerith)
- Loading branch information
1 parent
64623b1
commit 619e9ef
Showing
2 changed files
with
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Stringer } from "./api"; | ||
|
||
/** | ||
* Formats given value `x` as Fortran style Hollerith string. | ||
* | ||
* ``` | ||
* hstr("abc") // "3Habc" | ||
* hstr(123.45) // "6H123.45" | ||
* hstr("") // "0H" | ||
* hstr(null) // "" | ||
* ``` | ||
* | ||
* https://en.wikipedia.org/wiki/Hollerith_constant | ||
* | ||
* @param x | ||
*/ | ||
export const hstr: Stringer<any> = (x) => | ||
x != null ? ((x = x.toString()), `${x.length}H${x}`) : ""; |
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