tsm-utils
v0.6.1
Published
Default utils functions and configs used across projects
Readme
TSM Utils
Npm package with utility code shared across projects
Default Lint config
// eslint.config.js
export { lintConfig as default } from 'tsm-utils/lint';Functions
createAPI
export const api = createAPI('/api');
export const exampleApi = createAPI('https://api.example.com');handlePromise
HOF that automatically handles promisse rejections and adjusts return type. Optionally handles the error
type Foo = (bar: string) => Promise<string | undefined>;
export const foo: Foo = handlePromise(
async (bar: string) => {
// do something async
return '';
},
(error) => {
console.log(error);
},
);Classes
CustomSet
Create sets with support for set operations using any type by providing the equality function
type User = {
id: string;
name: string;
};
export class UserSet extends CustomSet<User> {
constructor(initialValues?: User[]) {
const equals = (x: User, y: User): boolean => x.id === y.id;
super(equals, initialValues);
}
};Publishing
- First clear the output folder
rm -rf dist- Transpile source code to js under /dist
npm run tsc- Publish the package
npm publish