Skip to content

Commit

Permalink
chore(strings): update exports, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 9, 2018
1 parent 653a175 commit e9c8ddc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/strings/src/api.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type Stringer<T> = (x: T) => string;
export type Stringer<T> = (x: T, ...xs: any[]) => string;
2 changes: 2 additions & 0 deletions packages/strings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export * from "./percent";
export * from "./radix";
export * from "./repeat";
export * from "./truncate";
export * from "./truncate-left";
export * from "./wrap";
23 changes: 23 additions & 0 deletions packages/strings/src/radix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,31 @@ export const radix: (radix: number, len: number, prefix?: string) => Stringer<nu
}
);

/**
* 8bit binary conversion preset.
*/
export const B8 = radix(2, 8);

/**
* 8bit hex conversion preset.
* Assumes unsigned inputs.
*/
export const U8 = radix(16, 2);

/**
* 16bit hex conversion preset.
* Assumes unsigned inputs.
*/
export const U16 = radix(16, 4);

/**
* 32bit hex conversion preset.
* Assumes unsigned inputs.
*/
export const U32 = radix(16, 8);

/**
* 64bit hex conversion preset (2x 32bit ints)
* Assumes unsigned inputs.
*/
export const U64 = (hi: number, lo: number) => U32(hi) + U32(lo);

0 comments on commit e9c8ddc

Please sign in to comment.