Skip to content

Commit

Permalink
simplify some method
Browse files Browse the repository at this point in the history
  • Loading branch information
lagden committed Oct 6, 2023
1 parent 5019e5d commit 44b798a
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 132 deletions.
188 changes: 96 additions & 92 deletions coverage/lcov.info
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,18 @@ DA:26,27
DA:27,27
DA:28,27
DA:29,39
DA:30,39
DA:30,3
DA:31,3
DA:32,3
DA:33,39
DA:32,39
DA:33,17
DA:34,17
DA:35,17
DA:35,4
DA:36,4
DA:37,4
DA:38,17
DA:39,39
DA:40,27
LF:40
LH:40
DA:37,17
DA:38,39
DA:39,27
LF:39
LH:39
BRDA:1,0,0,1
BRDA:9,1,0,5
BRDA:10,2,0,1
Expand All @@ -310,15 +309,15 @@ BRDA:12,4,0,3
BRDA:16,5,0,2
BRDA:26,6,0,27
BRDA:28,7,0,39
BRDA:30,8,0,4
BRDA:30,9,0,2
BRDA:30,10,0,1
BRDA:30,11,0,3
BRDA:33,12,0,36
BRDA:33,13,0,17
BRDA:33,14,0,17
BRDA:35,15,0,4
BRDA:40,16,0,20
BRDA:29,8,0,4
BRDA:29,9,0,2
BRDA:29,10,0,1
BRDA:29,11,0,3
BRDA:32,12,0,36
BRDA:32,13,0,17
BRDA:32,14,0,17
BRDA:34,15,0,4
BRDA:39,16,0,20
BRF:17
BRH:17
end_of_record
Expand Down Expand Up @@ -511,9 +510,11 @@ end_of_record
TN:
SF:src/lib/rnd.js
FN:6,rnd
FNF:1
FNH:1
FN:16,uuid
FNF:2
FNH:2
FNDA:3,rnd
FNDA:2,uuid
DA:1,1
DA:2,1
DA:3,1
Expand All @@ -522,20 +523,28 @@ DA:5,1
DA:6,1
DA:7,3
DA:8,3
DA:9,3
DA:10,3
DA:9,1
DA:10,1
DA:11,1
DA:12,1
DA:13,3
LF:13
LH:13
DA:13,1
DA:14,1
DA:15,1
DA:16,1
DA:17,1
DA:18,1
DA:19,2
DA:20,2
LF:20
LH:20
BRDA:1,0,0,1
BRDA:6,1,0,3
BRDA:9,2,0,2
BRDA:9,3,0,1
BRDA:11,4,0,1
BRF:5
BRH:5
BRDA:16,2,0,2
BRDA:18,3,0,1
BRDA:19,4,0,1
BRDA:19,5,0,1
BRF:6
BRH:6
end_of_record
TN:
SF:src/lib/set-css-vars.js
Expand Down Expand Up @@ -681,67 +690,37 @@ BRF:3
BRH:3
end_of_record
TN:
SF:src/lib/dom/prop.js
FN:7,getProp
FNF:1
FNH:1
FNDA:1,getProp
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
LF:9
LH:9
BRDA:1,0,0,1
BRDA:7,1,0,1
BRF:2
BRH:2
end_of_record
TN:
SF:src/lib/parse/boolean.js
FN:7,parseBoolean
FNF:1
FNH:1
FNDA:8,parseBoolean
FNDA:7,parseBoolean
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,8
DA:8,7
DA:9,2
DA:10,2
DA:11,6
DA:12,6
DA:13,8
DA:14,4
DA:15,4
DA:16,8
DA:17,8
LF:17
LH:17
DA:11,5
DA:12,7
DA:13,7
LF:13
LH:13
BRDA:1,0,0,1
BRDA:7,1,0,8
BRDA:7,1,0,7
BRDA:8,2,0,2
BRDA:11,3,0,6
BRDA:13,4,0,4
BRDA:14,5,0,3
BRDA:16,6,0,2
BRDA:16,7,0,1
BRDA:16,8,0,1
BRF:9
BRH:9
BRDA:11,3,0,5
BRDA:12,4,0,4
BRF:5
BRH:5
end_of_record
TN:
SF:src/lib/parse/number.js
FN:6,parseNumber
FN:7,parseNumber
FNF:1
FNH:1
FNDA:5,parseNumber
Expand All @@ -751,24 +730,25 @@ DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,5
DA:7,1
DA:8,5
DA:9,1
DA:9,5
DA:10,1
DA:11,4
DA:12,5
DA:13,1
DA:11,1
DA:12,4
DA:13,5
DA:14,1
DA:15,3
DA:16,5
LF:16
LH:16
DA:15,1
DA:16,3
DA:17,5
LF:17
LH:17
BRDA:1,0,0,1
BRDA:6,1,0,5
BRDA:8,2,0,1
BRDA:11,3,0,4
BRDA:12,4,0,1
BRDA:15,5,0,3
BRDA:7,1,0,5
BRDA:9,2,0,1
BRDA:12,3,0,4
BRDA:13,4,0,1
BRDA:16,5,0,3
BRF:6
BRH:6
end_of_record
Expand Down Expand Up @@ -912,7 +892,7 @@ BRH:8
end_of_record
TN:
SF:src/lib/url/get-url.js
FN:6,getURL
FN:7,getURL
FNF:1
FNH:1
FNDA:1,getURL
Expand All @@ -925,10 +905,11 @@ DA:6,1
DA:7,1
DA:8,1
DA:9,1
LF:9
LH:9
DA:10,1
LF:10
LH:10
BRDA:1,0,0,1
BRDA:6,1,0,1
BRDA:7,1,0,1
BRF:2
BRH:2
end_of_record
Expand Down Expand Up @@ -956,6 +937,29 @@ BRF:2
BRH:2
end_of_record
TN:
SF:src/lib/url/prop.js
FN:8,getProp
FNF:1
FNH:1
FNDA:1,getProp
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:10,1
LF:10
LH:10
BRDA:1,0,0,1
BRDA:8,1,0,1
BRF:2
BRH:2
end_of_record
TN:
SF:src/lib/url/qs.js
FN:6,qs
FNF:1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tadashi/common",
"version": "4.1.2",
"version": "4.2.0",
"description": "Common functions",
"type": "module",
"main": "./src/common.js",
Expand Down
4 changes: 2 additions & 2 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export {getData} from './lib/dom/data.js'
export {getProp} from './lib/dom/prop.js'
//
export {parseBoolean} from './lib/parse/boolean.js'
export {parseNumber} from './lib/parse/number.js'
Expand All @@ -10,6 +9,7 @@ export {removeStorage} from './lib/storage/remove.js'
export {setStorage} from './lib/storage/set.js'
//
export {fullURL, fullURL as fullUrl} from './lib/url/full-url.js'
export {getProp} from './lib/url/prop.js'
export {getURL, getURL as getUrl} from './lib/url/get-url.js'
export {params} from './lib/url/params.js'
export {qs} from './lib/url/qs.js'
Expand All @@ -28,7 +28,7 @@ export {kebabify} from './lib/kebabify.js'
export {noop} from './lib/noop.js'
export {obj2style} from './lib/obj2style.js'
export {removeLink} from './lib/remove-link.js'
export {rnd, rnd as uuid} from './lib/rnd.js'
export {rnd, uuid} from './lib/rnd.js'
export {setCssVars} from './lib/set-css-vars.js'
export {template} from './lib/template.js'
export {uniqueWords} from './lib/unique-words.js'
9 changes: 0 additions & 9 deletions src/lib/dom/prop.js

This file was deleted.

18 changes: 7 additions & 11 deletions src/lib/parse/boolean.js
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'
}
7 changes: 4 additions & 3 deletions src/lib/parse/number.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Converte o valor para número
* @param {*} v - Valor que será convertido para número
* @return {(number|any)} Se sucesso retorna o número
* Parses a value into a number, or returns the original value if it matches a specific format or cannot be converted.
*
* @param {*} v - The value to be parsed into a number.
* @returns {number|string} A numeric representation of the input value, or the original value if parsing is not possible.
*/
export function parseNumber(v) {
const regex = /^\d+\.(0+)?$/
Expand Down
25 changes: 16 additions & 9 deletions src/lib/rnd.js
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
}
Loading

0 comments on commit 44b798a

Please sign in to comment.