319 private links
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!
References the web APIs, where a lot of answers of stackoverflow can be found
I agree with many folks here on HN in that
null
andundefined
have important differences.undefined
appears when you access an invalid field, whilenull
appears when you access a valid, but empty field.
What does which operators in javascript?
Nano ID is nano-sized unique string ID generator for JavaScript. It’s truly small (130 bytes minified), URL-friendly, and it has no dependencies. Plus, it’s safe, secure, and fast.
Project link: https://github.com/ai/nanoid
A small library to generate unique ids. It is implemented in a lot of other languages too.
Limitations and workarounds about the number input.
From the UK government:
SVG is an excellent way to create interactive, resolution-independent vector graphics that will look great on any size screen. And the Snap.svg JavaScript library makes working with your SVG assets as easy as jQuery makes working with the DOM.
const { length, 0: first, [length - 1]: last } = arr;