Skip to content

Code snippets

Tokens for the replacement field of find and replace.

Token Effect
\U uppercase until \E
\L lowercase until \E
\u uppercase the next character
\l lowercase the next character

They work in JetBrains IDEs, VS Code, Notepad++, GNU sed and Perl. JavaScript String.replace has none; use a callback. Example: find (\w+), replace \u\L$1 (\1 in sed), hELLO becomes Hello.

Source: Replacement Text Case Conversion.

A replacement for $.getScript. In ES modules prefer import().

const getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.onload = () => resolve(script);
script.onerror = () => reject(new Error(`Failed to load script: ${url}`));
document.head.appendChild(script);
});
await getScript('https://example.com/library.js');
Terminal window
npm install yargs
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
const argv = yargs(hideBin(process.argv))
.option('o', { alias: 'option', type: 'boolean', default: false })
.parse();

For simple cases Node.js has the built-in util.parseArgs. yargs docs.

Name Description Code Language
Knex.js SQL query builder knex/knex Node.js
Faker Fake data generator faker-js/faker Node.js