Skip to content

Commit

Permalink
feat(strings): add hstr() (hollerith)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 13, 2019
1 parent 64623b1 commit 619e9ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/strings/src/hollerith.ts
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}`) : "";
1 change: 1 addition & 0 deletions packages/strings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./case";
export * from "./center";
export * from "./float";
export * from "./format";
export * from "./hollerith";
export * from "./pad-left";
export * from "./pad-right";
export * from "./parse";
Expand Down

0 comments on commit 619e9ef

Please sign in to comment.