Results for “safe”
Small, practical examples. Search by task or narrow things down below.
Print text containing percent characters literally
Bash Scripts: Never use untrusted text as the printf format string.
Bash Scripts✓ Tested
Render untrusted-looking input as literal text
Render untrusted-looking input as literal text with a small React component and explicit browser behavior.
React✓ Tested
Append a list item
Build a jQuery element with text and append it safely.
jQuery✓ Tested
Create nested folders
Create a folder and any missing parent folders in one call. Running the code again is safe when the folder already exists.
directory✓ Tested
Give a function an optional argument
Let callers omit a value while keeping nounset enabled.
optional argument✓ Tested
Handle a result with a discriminated union
Separate success data from an error message.
discriminated union✓ Tested
Read a nested optional value
Avoid dereferencing a missing nested object.
optional chaining✓ Tested
Update an object with a readonly input
Create a changed copy while retaining the original.
readonly✓ Tested
Validate an unknown value with a type guard
Check a field before treating unknown data as a typed object.
unknown✓ Tested
Validate the shape of an absolute URL
HTML: A URL input checks syntax, not whether a resource exists or is safe.
HTML✓ Tested