Skip to content

Commit

Permalink
Version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
shgysk8zer0 committed Oct 31, 2023
1 parent 5a3b487 commit 9c673f7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.2.4] - 2023-10-31

### Added
- Add utility function for Simple UIDs
- Add support for `credentialless` iframes [#44](https://github.com/shgysk8zer0/kazoo/issues/44)

## [v0.2.3] - 2023-07-19

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shgysk8zer0/kazoo",
"version": "0.2.3",
"version": "0.2.4",
"private": false,
"type": "module",
"description": "A JavaScript monorepo for all the things!",
Expand Down
22 changes: 22 additions & 0 deletions utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { isBare, resolveModule } from './module.js';

const funcs = new WeakMap();

// Math.log(Number.MAX_SAFE_INTEGER);
const LOG_MAX_SAFE_INTEGER = 36.7368005696771;

export function isStrictMode() {
// Probably always true
return typeof this === 'undefined';
Expand Down Expand Up @@ -405,6 +408,25 @@ export function random(arr) {
}
}

export function getSimpleUID({ radix = 36, padding = null, seperator = '-', timestamp = Date.now() } = {}) {
const date = timestamp.toString(radix);
const random = crypto.getRandomValues(new Uint32Array(1))[0].toString(radix);

if (typeof padding !== 'string' || padding.length === 0) {
return `${date}${seperator}${random}`;
} else if (padding.length !== 1) {
throw new TypeError('Padding must be a single character');
} else {
const length = Math.ceil(LOG_MAX_SAFE_INTEGER / Math.log(radix));
return `${date.padStart(length, padding)}${seperator}${random.padStart(length, padding)}`;
}
}

export function parseSimpleUID(uid, { radix = 36, seperator = '-' } = {}) {
const [date, random] = uid.split(seperator).map(str => parseInt(str, radix));
return { date: new Date(date), random };
}

export const toSpinalCase = str => str.replace(/[A-Z]/g, (m, i) => i === 0
? m.toLowerCase()
: `-${m.toLowerCase()}`);
Expand Down

0 comments on commit 9c673f7

Please sign in to comment.