You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript utilities: helper functions, classes, FP data structures, and type helpers. Zero dependencies (optional @js-toolkit/node-utils for build minification).
Install
yarn add @js-toolkit/utils
# or
npm install @js-toolkit/utils
import{tryGet}from'@js-toolkit/utils/tryGet';import{getErrorMessage}from'@js-toolkit/utils/getErrorMessage';constinput='{"key":"value"}';// e.g. from API or userconstvalue=tryGet(()=>JSON.parse(input)asRecord<string,unknown>,null);if(value===null){// parse failed}try{awaitfetch('/api/data');// or any async operation}catch(err: unknown){console.error(getErrorMessage(err));}
import{Option}from'@js-toolkit/utils/fp/Option';constvalue: string|null=null;// or from API, form, etc.constopt=Option.of(value);if(opt.nonEmpty()){console.log(opt.get());}constresult=opt.getOrElse('default');
debounce
import{debounce}from'@js-toolkit/utils/debounce';asyncfunctionfetchResults(query: string): Promise<void>{/* fetch and render */}constdebouncedSearch=debounce((query: string)=>voidfetchResults(query),300);debouncedSearch('foo');if(debouncedSearch.isPending){// call is queued}debouncedSearch.cancel();