Gathering detailed insights and metrics for @ndaidong/bellajs
Gathering detailed insights and metrics for @ndaidong/bellajs
Gathering detailed insights and metrics for @ndaidong/bellajs
Gathering detailed insights and metrics for @ndaidong/bellajs
npm install @ndaidong/bellajs
Typescript
Module System
Node Version
NPM Version
73.5
Supply Chain
98.9
Quality
80.4
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
666
Last Day
1
Last Week
3
Last Month
15
Last Year
666
11 Stars
168 Commits
3 Forks
1 Watching
2 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
12.0.1
Package Id
@ndaidong/bellajs@12.0.1
Unpacked Size
79.72 kB
Size
15.71 kB
File Count
137
NPM Version
10.8.2
Node Version
20.18.0
Publised On
26 Oct 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
200%
3
Compared to previous week
Last month
-82.8%
15
Compared to previous month
Last year
0%
666
Compared to previous year
3
Lightweight util for handling data type, string... in your Node.js and browser apps.
https://jsr.io/@ndaidong/bellajs
1import { genid } from "@ndaidong/bellajs"; 2 3for (let i = 0; i < 5; i++) { 4 console.log(genid()); 5}
You can use JSR packages without an install step using jsr:
specifiers:
1import { genid } from "jsr:@ndaidong/bellajs"; 2 3for (let i = 0; i < 5; i++) { 4 console.log(genid()); 5}
You can also use npm:
specifiers as before:
1import { genid } from "npm:@ndaidong/bellajs"; 2 3for (let i = 0; i < 5; i++) { 4 console.log(genid()); 5}
Or import from esm.sh
1import { genid } from "https://esm.sh/@ndaidong/bellajs"; 2 3for (let i = 0; i < 5; i++) { 4 console.log(genid()); 5}
https://www.npmjs.com/package/@ndaidong/bellajs
1npm i @ndaidong/bellajs 2# pnpm 3pnpm i @ndaidong/bellajs 4# yarn 5yarn add @ndaidong/bellajs 6# bun 7bun add @ndaidong/bellajs
1import { genid } from "@ndaidong/bellajs"; 2 3for (let i = 0; i < 5; i++) { 4 console.log(genid()); 5}
You can also use CJS style:
1const { genid } = require("@ndaidong/bellajs"); 2 3for (let i = 0; i < 5; i++) { 4 console.log(genid()); 5}
1<script type="module"> 2 import { genid } from "https://esm.sh/@ndaidong/bellajs"; 3 // import { genid } from 'https://unpkg.com/@ndaidong/bellajs/esm/mod.js'; 4 5 for (let i = 0; i < 5; i++) { 6 console.log(genid()); 7 } 8</script>
.isArray(Anything val)
.isBoolean(Anything val)
.isDate(Anything val)
.isEmail(Anything val)
.isEmpty(Anything val)
.isFunction(Anything val)
.isInteger(Anything val)
.isLetter(Anything val)
.isNil(Anything val)
.isNull(Anything val)
.isNumber(Anything val)
.isObject(Anything val)
.isString(Anything val)
.isUndefined(Anything val)
.ucfirst(String s)
.ucwords(String s)
.escapeHTML(String s)
.unescapeHTML(String s)
.slugify(String s)
.stripTags(String s)
.stripAccent(String s)
.truncate(String s, Number limit)
.replaceAll(String s, String|Array search, String|Array replace)
clone(Anything val)
Make a deep copy of a variable.
1import { clone } from "@ndaidong/bellajs"; 2 3const b = [ 4 1, 5 5, 6 0, 7 "a", 8 -10, 9 "-10", 10 "", 11 { 12 a: 1, 13 b: "Awesome", 14 }, 15]; 16 17const cb = clone(b); 18console.log(cb);
cb now has the same values as b, while the properties are standalone, not reference. So that:
1cb[7].a = 2; 2cb[7].b = "Noop"; 3 4console.log(b[7]);
What you get is still:
1{ 2 a: 1, 3 b: 'Awesome' 4}
copies(Object source, Object target[[, Boolean requireMatching], Array excepts])
Copy the properties from source to target.
After this action, target will be modified.
1import { copies } from "@ndaidong/bellajs"; 2 3const a = { 4 name: "Toto", 5 age: 30, 6 level: 8, 7 nationality: { 8 name: "America", 9 }, 10}; 11const b = { 12 level: 4, 13 IQ: 140, 14 epouse: { 15 name: "Alice", 16 age: 27, 17 }, 18 nationality: { 19 long: "18123.123123.12312", 20 lat: "98984771.134231.1234", 21 }, 22}; 23 24copies(a, b); 25console.log(b);
Output:
1{ 2 level: 8, 3 IQ: 140, 4 epouse: { 5 name: 'Alice', 6 age: 27 7 }, 8 nationality: { 9 long: '18123.123123.12312', 10 lat: '98984771.134231.1234', 11 name: 'America' 12 }, 13 name: 'Toto', 14 age: 30 15}
pick(Array arr [, Number count = 1])
Randomly choose N elements from array.
1import { pick } from "@ndaidong/bellajs"; 2 3const arr = [1, 3, 8, 2, 5, 7]; 4pick(arr, 2); // --> [3, 5] 5pick(arr, 2); // --> [8, 1] 6pick(arr); // --> [3] 7pick(arr); // --> [7]
sort(Array arr [, Function compare])
Sort the array using a function.
1import { sort } from "@ndaidong/bellajs"; 2 3const fn = (a, b) => { 4 return a < b ? 1 : a > b ? -1 : 0; 5}; 6 7sort([3, 1, 5, 2], fn); // => [ 1, 2, 3, 5 ]
sortBy(Array arr, Number order, String property)
Sort the array by specific property and direction.
1import { sortBy } from "@ndaidong/bellajs"; 2 3const players = [ 4 { 5 name: "Jerome Nash", 6 age: 24, 7 }, 8 { 9 name: "Jackson Valdez", 10 age: 21, 11 }, 12 { 13 name: "Benjamin Cole", 14 age: 23, 15 }, 16 { 17 name: "Manuel Delgado", 18 age: 33, 19 }, 20 { 21 name: "Caleb McKinney", 22 age: 28, 23 }, 24]; 25 26const result = sortBy(players, -1, "age"); 27console.log(result);
shuffle(Array arr)
Shuffle the positions of elements in an array.
1import { shuffle } from "@ndaidong/bellajs"; 2 3shuffle([1, 3, 8, 2, 5, 7]);
unique(Array arr)
Remove all duplicate elements from an array.
1import { unique } from "@ndaidong/bellajs"; 2 3unique([1, 2, 3, 2, 3, 1, 5]); // => [ 1, 2, 3, 5 ]
curry(fn)
Make a curried function.
1import { curry } from "@ndaidong/bellajs"; 2 3const sum = curry((a, b, c) => { 4 return a + b + c; 5}); 6 7sum(3)(2)(1); // => 6 8sum(1)(2)(3); // => 6 9sum(1, 2)(3); // => 6 10sum(1)(2, 3); // => 6 11sum(1, 2, 3); // => 6
compose(f1, f2, ...fN)
Performs right-to-left function composition.
1import { compose } from "@ndaidong/bellajs"; 2 3const f1 = (name) => { 4 return `f1 ${name}`; 5}; 6const f2 = (name) => { 7 return `f2 ${name}`; 8}; 9const f3 = (name) => { 10 return `f3 ${name}`; 11}; 12 13const addF = compose(f1, f2, f3); 14 15addF("Hello"); // => 'f1 f2 f3 Hello' 16 17const add1 = (num) => { 18 return num + 1; 19}; 20 21const mult2 = (num) => { 22 return num * 2; 23}; 24 25const add1AndMult2 = compose(add1, mult2); 26add1AndMult2(3); // => 7 27// because multiple to 2 first, then add 1 late => 3 * 2 + 1
pipe(f1, f2, ...fN)
Performs left-to-right function composition.
1import { pipe } from "@ndaidong/bellajs"; 2 3const f1 = (name) => { 4 return `f1 ${name}`; 5}; 6const f2 = (name) => { 7 return `f2 ${name}`; 8}; 9const f3 = (name) => { 10 return `f3 ${name}`; 11}; 12 13const addF = pipe(f1, f2, f3); 14 15addF("Hello"); // => 'f3 f2 f1 Hello' 16 17const add1 = (num) => { 18 return num + 1; 19}; 20 21const mult2 = (num) => { 22 return num * 2; 23}; 24 25const add1AndMult2 = pipe(add1, mult2); 26add1AndMult2(3); // => 8 27// because add 1 first, then multiple to 2 late => (3 + 1) * 2
formatDateString(Date | Timestamp [, String locale [, Object options]])
1import { formatDateString } from "@ndaidong/bellajs"; 2 3const today = new Date(); 4 5formatDateString(today); // => Jan 3, 2022, 8:34:28 PM GMT+7 6 7// custom format 8formatDateString(today, { 9 dateStyle: "short", 10 timeStyle: "short", 11 hour12: true, 12}); // => 1/3/22, 8:34 PM 13 14// custom locale 15formatDateString(today, "zh"); // => 2022年1月3日 GMT+7 下午8:34:28 16 17// custom lang and format 18formatDateString(today, "zh", { 19 dateStyle: "short", 20 timeStyle: "long", 21 hour12: true, 22}); // => 2022/1/3 GMT+7 下午8:34:28 23 24formatDateString(today, "vi"); // => 20:34:28 GMT+7, 3 thg 1, 2022 25formatDateString(today, "vi", { 26 dateStyle: "full", 27 timeStyle: "full", 28}); // => 20:34:28 Giờ Đông Dương Thứ Hai, 3 tháng 1, 2022
formatTimeAgo(Date | Timestamp [, String locale [, String justnow]])
1import { formatTimeAgo } from "@ndaidong/bellajs";
2
3const today = new Date();
4
5const yesterday = today.setDate(today.getDate() - 1);
6formatTimeAgo(yesterday); // => 1 day ago
7
8const current = new Date();
9const aLittleWhile = current.setHours(current.getHours() - 3);
10formatTimeAgo(aLittleWhile); // => 3 hours ago
11
12// change locale
13formatTimeAgo(aLittleWhile, "zh"); // => 3小时前
14formatTimeAgo(aLittleWhile, "vi"); // => 3 giờ trước
The last param justnow
can be used to display a custom 'just now' message,
when the distance is lesser than 1s.
1const now = new Date();
2const aJiff = now.setTime(now.getTime() - 100);
3formatTimeAgo(aJiff); // => 'just now'
4formatTimeAgo(aJiff, "fr", "à l'instant"); // => à l'instant
5formatTimeAgo(aJiff, "ja", "すこし前"); // => すこし前
These two functions based on recent features of built-in object Intl
.
Please refer the following resources for more info:
randint([Number min [, Number max]])
Returns a number between min
and max
1import { randint } from "@ndaidong/bellajs"; 2 3randint(); // => a random integer 4randint(1, 5); // => a random integer between 3 and 5, including 1 and 5
genid([Number length [, String prefix]])
Create random ID string.
1import { genid } from "@ndaidong/bellajs"; 2 3genid(); // => random 32 chars 4genid(16); // => random 16 chars 5genid(5); // => random 5 chars 6genid(5, "X_"); // => X_{random 3 chars}
Since v12.x.x, we switched to Deno platform, and use DNT to build Node.js packages.
1git clone https://github.com/ndaidong/bellajs.git 2cd bellajs 3 4# test 5deno test 6 7# build npm packages 8deno task build 9 10cd npm 11node test_runner.js
The MIT License (MIT)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/11 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-02
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More