222 private links
Numbers:
const formatter = Intl.NumberFormat(LOCALE, { notation: 'compact' })
Currency:
Intl.NumberFormat(LOCALE, {
notation: 'compact',
style: 'currency',
currency: 'ZWD'
})
It uses WebGL for it.
Using JS to generate a default avatar with one letter:
function genAvatar(name) {
try {
// Match General_Category=Letter
const match = name.match(/\p{L}/u);
return (match && match[0]) || null;
} catch {
return name[0] || null;
}
}
In the last 14 months (from Oct-2021 to Nov-2022), DevJobsScanner has analyzed more than 12M developer jobs.
- JS/TS
- Python
- Java
- C#
- PHP
- C/C++
- Ruby
- Go
How to handle fetch API errors ?
It throws on API Network Error only...
A curated list of algorithms sorted in two categories: Beginner and Advanced
Specific questions on the JS language
JavaScript Repository of TheAlgorithms, which implements various algorithms and data structures in JavaScript.
For education only
const productIds = [123, 456, undefined, 789]
const products = productIds
.map(getProduct)
.filter((item): item is Product => item !== undefined)
Would be my first pick to use in a JS environment
Often forgotten, it might be useful
import { v4 as uuidv4 } from 'uuid'
export const useId = () => {
const prefix = uuidv4()
const $id = (name: string) => `${prefix}-${name}`
return { $id }
}
It can work with the crypto module too.
document.designMode controls whether the entire document is editable. Values are "on" and "off".
I learned about what WebDAV is on the way: https://en.wikipedia.org/wiki/WebDAV
Only 8KB gzipped! And fast installed with only one file :)
const moreInfos = { info: "Please go to the desk." }
return {
address: "20B Rue Lafayette",
postcode: "75009",
...(moreInfos !== undefined && { moreInfos })
}
In JavaScript, primitive values are Number, String, Boolean, Undefined, Symbol, and BigInt. Other data types are passed by reference, which means that the variable is given instead of just a copy. Modifications happen in-place.
An example of Weakmap: https://gist.github.com/PaulRosset/0d4e3a9b9af20f9997b41d15f70c8808#file-weak-map-js. Everything can be a key.
Clean code is not only concise code, but more importantly, it is readable. A rule of thumb when writing code, is to write code as if comments didn’t exist. The code should be self-explanatory.
- booleans should always have a prefix like "is", "has", or "was"
and other JS tips
The thing is some are already on https://1loc.dev/
Others can be added :)
A useful utility 👍
Unjs projects are definitely worth trying!