-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate webpack to vite, karma to web-test-runner (#1111)
Co-authored-by: Trevor Manz <trevor.j.manz@gmail.com> Co-authored-by: Peter Kerpedjiev <pkerpedjiev@gmail.com>
- Loading branch information
1 parent
04df604
commit e987a0f
Showing
209 changed files
with
17,811 additions
and
23,217 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
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,36 @@ | ||
import { v4 } from '@lukeed/uuid'; | ||
|
||
/** | ||
* | ||
* Returns a randomly generated uuid v4 compliant slug which conforms to a set | ||
* of "nice" properties, at the cost of some entropy. Currently this means one | ||
* extra fixed bit (the first bit of the uuid is set to 0) which guarantees the | ||
* slug will begin with [A-Za-f]. For example such slugs don't require special | ||
* handling when used as command line parameters (whereas non-nice slugs may | ||
* start with `-` which can confuse command line tools). | ||
* | ||
* Adapted from `slugid` to avoid the need a Buffer polyfill. | ||
* | ||
* @see https://github.com/taskcluster/slugid/blob/ce3bf62c6c50b7da014ce568e4510944d306d6f0/slugid.js#L63-L83 | ||
*/ | ||
function nice() { | ||
// convert string uuid to bytes (without Buffer); | ||
const uuid = v4(); | ||
const integers = uuid | ||
.replace(/-/gi, '') // remove '-' separator of string hex | ||
.match(/[\dA-F]{2}/gi) // match each hex pair | ||
.map(s => parseInt(s, 16)); | ||
const bytes = new Uint8Array(integers); | ||
|
||
bytes[0] &= 0x7f; // unset first bit to ensure [A-Za-f] first char | ||
|
||
return btoa(bytes) | ||
.replace(/\+/g, '-') // Replace + with - (see RFC 4648, sec. 5) | ||
.replace(/\//g, '_') // Replace / with _ (see RFC 4648, sec. 5) | ||
.substring(0, 22); // Drop '==' padding | ||
} | ||
|
||
export default { | ||
v4, | ||
nice, | ||
} |
Oops, something went wrong.