aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils/glyph_hash.ts
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-01 01:02:58 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-01 01:02:58 +0200
commitcac85db02ff00732cf75d473dc3411332f33d845 (patch)
tree5f244968a905eb3888434b3f60cbf05d2b652207 /src/lib/utils/glyph_hash.ts
parenta7cf03c192470cbab13edeb1aec99e0c66dede10 (diff)
Apply formatting
Diffstat (limited to 'src/lib/utils/glyph_hash.ts')
-rw-r--r--src/lib/utils/glyph_hash.ts60
1 files changed, 21 insertions, 39 deletions
diff --git a/src/lib/utils/glyph_hash.ts b/src/lib/utils/glyph_hash.ts
index b704569..7ac6448 100644
--- a/src/lib/utils/glyph_hash.ts
+++ b/src/lib/utils/glyph_hash.ts
@@ -1,55 +1,37 @@
export type GlyphHash = GlyphHashFragment[];
type GlyphHashFragment = {
- glyph: string,
- color: string
+ glyph: string;
+ color: string;
};
const internals = {
- kDehyphenRegex: /[-]/g,
- kSplitterRegex: /.{1,8}/g,
- kGlyphs: [
- '☽',
- '☆',
- '♢',
- '♡',
- '╱',
- '╲',
- '╳',
- '〰',
- '▷',
- '⏊',
- '〒',
- '▢',
- '◯',
- '⏃',
- '⏀',
- '⏆'
- ],
- unexpectedUUIDLength: class UnexpectedUUIDLength extends Error {
- name = 'UnexpectedUUIDLength';
- message = 'The provided string was not a valid UUIDv4, please provide a 32 character long string'
- }
+ kDehyphenRegex: /[-]/g,
+ kSplitterRegex: /.{1,8}/g,
+ kGlyphs: ['☽', '☆', '♢', '♡', '╱', '╲', '╳', '〰', '▷', '⏊', '〒', '▢', '◯', '⏃', '⏀', '⏆'],
+ unexpectedUUIDLength: class UnexpectedUUIDLength extends Error {
+ name = 'UnexpectedUUIDLength';
+ message =
+ 'The provided string was not a valid UUIDv4, please provide a 32 character long string';
+ }
};
// Return a glyph with color based on a 4 byte fragment of a UUIDv4
const getGlyphHashFragment = function (uuidFragment: string): GlyphHashFragment {
-
- const glyphIndex = parseInt(uuidFragment.substring(0, 2), 16) % 16;
- return {
- glyph: internals.kGlyphs[glyphIndex],
- color: `#${uuidFragment.substring(2, 8)}`
- };
+ const glyphIndex = parseInt(uuidFragment.substring(0, 2), 16) % 16;
+ return {
+ glyph: internals.kGlyphs[glyphIndex],
+ color: `#${uuidFragment.substring(2, 8)}`
+ };
};
// Return an array of glyphs based on a UUIDv4
export const getGlyphHash = function (uuid: string): GlyphHash {
+ const dehyphenedUuid = uuid.replace(/[-]/g, '');
- const dehyphenedUuid = uuid.replace(/[-]/g, '');
-
- if (dehyphenedUuid.length !== 32) {
- throw new internals.unexpectedUUIDLength();
- }
+ if (dehyphenedUuid.length !== 32) {
+ throw new internals.unexpectedUUIDLength();
+ }
- const hashFragments = dehyphenedUuid.match(internals.kSplitterRegex);
- return hashFragments.map(getGlyphHashFragment);
+ const hashFragments = dehyphenedUuid.match(internals.kSplitterRegex);
+ return hashFragments.map(getGlyphHashFragment);
};