4 Matching Annotations
- Nov 2021
-
blog.decipher.dev blog.decipher.dev
-
Determine if the string's length is greater than num. Return the string truncated to the desired length, with '...' appended to the end of the original string. Copyconst ellipsis = (str: string, num: number = str.length, ellipsisStr = "...") => str.length >= num ? str.slice(0, num >= ellipsisStr.length ? num - ellipsisStr.length : num) + ellipsisStr : str;
-
-
-
Check whether a value is defined (non-nullable), meaning it is neither `null` or `undefined`. This can be useful as a type guard, as for example, `[1, null].filter(Boolean)` does not always type-guard correctly.
-
-
-
import {isDefined} from 'ts-extras'; [1, null, 2, undefined].filter(isDefined); //=> [1, 2]
Tags
Annotators
URL
-