Results for “script”
Small, practical examples. Search by task or narrow things down below.
Prevent a variable value from expanding as a filename pattern
Bash Scripts: Quote a variable to pass its literal contents even when matching filenames exist.
Bash Scripts✓ Tested
Prevent runtime changes to top-level properties
JavaScript: Object.freeze prevents ordinary top-level mutations; Reflect.set reports the rejected update without throwing.
JavaScript✓ Tested
Prevent runtime changes to top-level properties
TypeScript: Object.freeze prevents ordinary top-level mutations; Reflect.set reports the rejected update without throwing.
TypeScript✓ Tested
Print a number with two decimal places
JavaScript: Format a small decimal value consistently for display.
JavaScript✓ Tested
Print a number with two decimal places
TypeScript: Format a small decimal value consistently for display.
TypeScript✓ Tested
Print text containing percent characters literally
Bash Scripts: Never use untrusted text as the printf format string.
Bash Scripts✓ Tested
Produce a lazy sequence with a generator
JavaScript: A generator yields one value per iteration without building an intermediate array.
JavaScript✓ Tested
Produce a lazy sequence with a generator
TypeScript: A generator yields one value per iteration without building an intermediate array.
TypeScript✓ Tested
Read a line without losing backslashes
Bash Scripts: Read a line without losing backslashes with a small standalone Bash program.
Bash Scripts✓ Tested
Read a nested value safely
Combine optional chaining with nullish coalescing in JavaScript.
JavaScript✓ Tested
Read a string’s character length
Bash Scripts: Bash parameter length counts characters under the current locale.
Bash Scripts✓ Tested
Read a URL query parameter
Parse a URL with the standard JavaScript URL API.
JavaScript✓ Tested