-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
141 additions
and
132 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 was deleted.
Oops, something went wrong.
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,17 +1,13 @@ | ||
/** | ||
* Converte o valor para boolean | ||
* @param {*} v - Valor que será convertido para boolean | ||
* @param {boolean} force - Força a conversão | ||
* @return {(boolean|any)} Se sucesso retorna o boolean | ||
* Parses a value into a boolean. | ||
* | ||
* @param {*} v - The value to be parsed into a boolean. | ||
* @returns {boolean} A boolean representation of the input value. | ||
*/ | ||
export function parseBoolean(v, force = true) { | ||
export function parseBoolean(v) { | ||
if (typeof v === 'boolean') { | ||
return v | ||
} | ||
const _v = String(v) | ||
const boolRegex = /^(?:true|false|1|0)$/i | ||
if (boolRegex.test(_v)) { | ||
return _v.toLowerCase() === 'true' || _v === '1' | ||
} | ||
return force ? Boolean(v) : v | ||
const _v = String(v).toLowerCase() | ||
return _v === 'true' || _v === '1' | ||
} |
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,13 +1,20 @@ | ||
/** | ||
* Gerador de id aleatório | ||
* @param {boolean} [removeDash=true] - remove o dash ("-") do uuid | ||
* @return {string} Retorna o uuid ou hexadecimal aleatório | ||
* Generates a random hexadecimal string by combining a random number and the current timestamp. | ||
* | ||
* @returns {string} A random hexadecimal string. | ||
*/ | ||
export function rnd(removeDash = true) { | ||
if (globalThis?.crypto?.randomUUID) { | ||
const _uuid = globalThis.crypto.randomUUID() | ||
return removeDash ? _uuid.replaceAll('-', '') : _uuid | ||
} | ||
/* c8 ignore next */ | ||
export function rnd() { | ||
return Number(Math.random()).toString(16).slice(2, 8) + Date.now().toString(16) | ||
} | ||
|
||
/** | ||
* Generates a UUID (Universally Unique Identifier) using the browser's crypto API or a random string. | ||
* | ||
* @param {boolean} [removeDash=true] - Whether to remove dashes from the generated UUID. | ||
* @returns {string} A UUID string. | ||
*/ | ||
export function uuid(removeDash = true) { | ||
/* c8 ignore next */ | ||
const _uuid = globalThis?.crypto?.randomUUID() ?? rnd() | ||
return removeDash ? _uuid.replaceAll('-', '') : _uuid | ||
} |
Oops, something went wrong.