Comparing version 11.1.3 to 11.2.0
{ | ||
"version": "11.1.3", | ||
"version": "11.2.0", | ||
"name": "bellajs", | ||
@@ -12,9 +12,5 @@ "description": "A useful helper for any javascript program", | ||
"main": "./src/main.js", | ||
"exports": { | ||
"import": "./src/main.js", | ||
"require": "./dist/bella.js" | ||
}, | ||
"type": "module", | ||
"engines": { | ||
"node": ">= 18" | ||
"node": ">= 18.4" | ||
}, | ||
@@ -26,8 +22,7 @@ "scripts": { | ||
"test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true --env=jsdom", | ||
"build": "node build.js src/main.js", | ||
"reset": "node reset" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "^0.20.1", | ||
"eslint": "^8.56.0", | ||
"eslint": "^9.2.0", | ||
"globals": "^15.2.0", | ||
"jest": "^29.7.0", | ||
@@ -34,0 +29,0 @@ "jest-environment-jsdom": "^29.7.0" |
@@ -7,6 +7,5 @@ BellaJS | ||
[![NPM](https://badge.fury.io/js/bellajs.svg)](https://badge.fury.io/js/bellajs) | ||
![CodeQL](https://github.com/ndaidong/bellajs/workflows/CodeQL/badge.svg) | ||
![CI test](https://github.com/ndaidong/bellajs/workflows/ci-test/badge.svg) | ||
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/bellajs/badge.svg)](https://coveralls.io/github/ndaidong/bellajs) | ||
![CodeQL](https://github.com/ndaidong/bellajs/workflows/CodeQL/badge.svg) | ||
[![CodeFactor](https://www.codefactor.io/repository/github/ndaidong/bellajs/badge)](https://www.codefactor.io/repository/github/ndaidong/bellajs) | ||
@@ -13,0 +12,0 @@ # Contents |
@@ -62,3 +62,3 @@ /** | ||
if (excepts.length > 0 && excepts.includes(k)) { | ||
continue // eslint-disable-line no-continue | ||
continue | ||
} | ||
@@ -65,0 +65,0 @@ if (!matched || (matched && hasProperty(dest, k))) { |
@@ -30,3 +30,3 @@ // utils / date | ||
return locale.language !== '' | ||
} catch (err) { | ||
} catch { | ||
return false | ||
@@ -33,0 +33,0 @@ } |
// utils / random | ||
export const randint = (min = 0, max = 1e6) => { | ||
return Math.floor(Math.random() * (max - min + 1)) + min | ||
} | ||
const crypto = globalThis.crypto | ||
export const genid = (len = 32, prefix = '') => { | ||
let s = prefix | ||
for (let i = 0; i < len; i++) { | ||
const nums = crypto.getRandomValues(new Uint32Array(len)) | ||
for (let i = 0; i < nums.length; i++) { | ||
const n = nums[i].toString(36) | ||
const r = Math.random() | ||
const k = Math.floor(r * 36) | ||
const c = k.toString(36) | ||
s += (k > 9 && r > 0.3 && r < 0.7) ? c.toUpperCase() : c | ||
const c = n.charAt(Math.floor(r * n.length)) | ||
s += (r > 0.3 && r < 0.7) ? c.toUpperCase() : c | ||
} | ||
return s.substring(0, len) | ||
} | ||
export const randint = (min = 0, max = 1e6) => { | ||
const byteArray = new Uint8Array(1) | ||
crypto.getRandomValues(byteArray) | ||
const floatNum = '0.' + byteArray[0].toString() | ||
return Math.floor(floatNum * (max - min + 1)) + min | ||
} |
@@ -136,7 +136,9 @@ // utils / string | ||
return stripAccent(s) | ||
.normalize('NFKD') | ||
.replace(/[\u0300-\u036f]/g, '') | ||
.trim() | ||
.toLowerCase() | ||
.replace(/\W+/g, ' ') | ||
.replace(/\s+/g, ' ') | ||
.replace(/\s/g, delimiter) | ||
.replace(/[^a-z0-9 -]/g, '') | ||
.replace(/\s+/g, delimiter) | ||
.replace(new RegExp(`${delimiter}+`, 'g'), delimiter) | ||
} |
@@ -240,6 +240,6 @@ // string.test | ||
text: 'Sur l\'année 2015', | ||
expectation: 'sur-l-annee-2015', | ||
expectation: 'sur-lannee-2015', | ||
}, | ||
{ | ||
text: 'Nghị luận tác phẩm "Đường kách mệnh" của Hồ Chí Minh', | ||
text: 'Nghị luận tác phẩm "Đường kách mệnh" của Hồ Chí Minh?!', | ||
expectation: 'nghi-luan-tac-pham-duong-kach-menh-cua-ho-chi-minh', | ||
@@ -246,0 +246,0 @@ }, |
49971
23
1452
525