Tag: js
-
Streams in Vite
I’m trying to use N3 to parse and query Turtle files in a Vite/Vue 3 project. The N3 readme says “N3.js seamlessly works in browsers via webpack or browserify” and I had trouble interpreting what that would mean in a Vite context. I made an attempt at properly learning all about bundling, but I did…
-
Sort empty strings last
You want to sort a list of strings in JavaScript, but some of the strings are empty, and you want those to come last. localeCompare is your friend, but it places empty strings first. The solution is a bit of boolean sweetness: [“foo”, “”, “bar”].sort((a, b) => a && b ? a.localeCompare(b) : !a -…
-
Comma, comma & and
I recently had to concatenate author names with commas and an ampersand in the following manner: commaAnd([‘Emir Jong’]); // becomes: “Emir Jong” commaAnd([‘Kristian Josefsen’, ‘Tetyana Bohuňková’]); // becomes: “Kristian Josefsen & Tetyana Bohuňková” commaAnd([‘Luana Ferreira Carvalho’, ‘Jian Tu’, ‘Ambessa Afwerki’]); // becomes: “Luana Ferreira Carvalho, Jian Tu & Ambessa Afwerki” Here are a few implementations…
-
A cryptocurrency-mining bot brute-forced into my WordPress site
Someone brute-forced into a client’s WordPress site and added cryptomining js. Good thing they knocked down an HTML div on their way out!