-
-
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.
refactor(strings): replace hex formatters w/ thi.ng/hex
- add thi.ng/hex dependency - replace U8/16/24/32/64 - refactor uuid()
- Loading branch information
1 parent
b31c872
commit 6d7446c
Showing
3 changed files
with
34 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,22 @@ | ||
import { U8 } from "./radix"; | ||
import { U16BE, U32BE, U48BE } from "@thi.ng/hex"; | ||
|
||
/** | ||
* Returns UUID formatted string of given byte array from optional start | ||
* index `i` (default: 0). Array must have min. length 16. | ||
* | ||
* @param id | ||
* @param i | ||
* @remarks | ||
* This is the same function as {@link @thi.ng/random#uuid}. | ||
* | ||
* @param id - | ||
* @param i - | ||
*/ | ||
export const uuid = (id: ArrayLike<number>, i = 0) => | ||
[ | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
].join(""); | ||
U32BE(id, i) + | ||
"-" + | ||
U16BE(id, i + 4) + | ||
"-" + | ||
U16BE(id, i + 6) + | ||
"-" + | ||
U16BE(id, i + 8) + | ||
"-" + | ||
U48BE(id, i + 10); |