TypeScript utility library for the GO Digital modern stack
npm install @growthops/ext-ts
Will trim the leading and trailing whitespace from the supplied string.
Used to build a function that will join the supplied array of strings together using the glue string. Functionaly identical to Array.prototype.join().
Used to build a function that will replace the supplied pattern with the replacement string. Functionally identical to String.prototype.replace().
Calls the supplied function the specified number of times. The function (fn) should take no arguments, and return nothing.
Example
``js
import {repeat} from '@growthops/ext-ts';
repeat(() => {
console.log('Hello!');
}, 5); // Will print "Hello!" to the console 5 times.
`
Determines whether the suppied string, array, or record is empty, eg. '', [], or {} respectively.
Complement of isEmpty.
Determines whether the two supplied objects are not equal. Doesn't handle cyclical data structures.
Determines whether the supplied input is not null or undefined.
Execute the function fn if input is not nil. input will be passed to fn as its first argument, with any remaining arguments passed to attempt following.
Determines whether the input is a record type and it has a key with the supplied value.
Determines whether the supplied input has been populated (not null, undefined, '', [], or {}).
Complement of isPopulated.
Generates a Picsum image URL based on the provided width and aspect ratio. Optionally supports specific Picsum image ID's.
Generates a test image record compatible with the DatoCMS ResponsiveImageType.
Takes a string or an array of strings consisting of newlines, tabs, and/or multiple spaces and returns a single collapsed string with only one space between each "word".
Example 1
`js
import {collapse} from '@growthops/ext-ts';
collapse(
foo
bar
baz);
// Returns: 'foo bar baz'
`
Example 2
`js
import {collapse} from '@growthops/ext-ts';
collapse([
'foo',
bar
baz
,
]);
// Returns: 'foo bar baz'
`
Creates an IntersectionObserver attached to the associated ref toggling isVisible when the object comes into view. The isDirty will be set to true once the object becomes visible and then remain true thereafter — useful for once-off events (scroll into view animations for instance).
Example
`js
import {useOnScreen} from '@growthops/ext-ts';
const Example = () => {
const {ref, isVisible} = useOnScreen
return (
$3
Creates a function that will evolve the supplied data using the
partial record. The partial record will be merged with the data, and the result will be returned. The partial record can be comprised of concrete values, or of functions that will be called with the current respective key's value and the result of the function will be used as the new value.Example
`js
import {useState, useCallback} from 'react';
import {evolve} from '@growthops/ext-ts';type State = {
clicked: boolean;
count: number;
}
const Clicker = () => {
const [state, setState] = useState({count: 0});
const handleClick = useCallback(() => {
setState(evolve({
clicked: true,
count: x => x + 1
}));
});
return (
{state.count}
);
};
`Aspect Ratios

$3
A lookup table of common aspect ratios in their fractional form (eg. 1.5 for Film).
$3
A lookup table of common aspect ratios in their notational string form (eg. '3:2' for Film).
Result
$3
Guard function for narrowing a
Result to a Success.$3
Guard function for narrowing a
Result to a Failure.$3
Utility function for quickly creating a
Success.$3
Utility function for quickly creating a
Failure.$3
Utility function for converting a
Promise into a Promise. The formatter function supplied is responsible for converting the type returned by the successful promise into the success type encapsulated by the result. The _optional_ errorHandler is responsible for converting the type returned by the failed promise into the failure type encapsulated by the result.Types
$3
Constructs a type where
T can be undefined or null (equivalent to T | null | undefined`).