tsut
is a set of generic utilities useful to all TypeScript programmers.
It's designed to be as generic and simple as possible. The utilities are just those that should be familiar to all programmers.
tsut
should be useful regardless of whether you're doing client or server work, and regardless of the framework you choose to use.
It does not define new data structures, just functions that are useable on their own --
so you can use it for only one utility without bringing in any baggage, and just write normal TypeScript code.
The utilities are divided into modules for better organization,
but you can use a single import import * as u from "tsut"
and use any function from that.
npm install --save andy-hanson/tsut#bin # Latest
npm install --save tsut # Stable
You must use "target": "es6"
and "moduleResolution": "node"
(or "module": "commonjs"
) in your tsconfig.json
.
import * as u from "tsut";
console.log(u.difference([1, 2, 3], [3, 1])) // Set { 2 }
The main modules are:
Module | For |
---|---|
option |
For using Option s (`Option = T |
function |
Common higher-order functions. |
seq |
For using Iterable s. |
asyncSeq |
For using AsyncIterable s. |
parallel |
Like asyncSeq but runs operations in parallel. |
async |
For using Promise s and async functions. |
array |
Array helpers. |
string |
For using String s. |
map |
For using Map s. |
set |
For using Set s. |
Other modules are:
Doc | Source | For |
---|---|---|
misc |
Other useful functions. | |
math |
For using number s. |
|
range |
Ranges of numbers. | |
tuple |
For using tuples. | |
types |
Easier typeof tests. |
|
reflect |
Common Proxy s. |
|
shims |
ES-next shims. | |
builder |
Builders for data structures. Used internally by seq and asyncSeq . |
X | Why |
---|---|
Data structures | typescript-collections |
Random utilities | chance |
Date utilities | moment |
More math utilities | mathjs |
File an issue if you have trouble using tsut.
- Fork the repository.
npm install
andnpm run all
(If this didn't work for you, file an issue.)- Make a change to a module, e.g.
src/array.ts
- If adding a new module, remember to add it to
index.ts
. Don't use a default export because that can't be re-exported.
- If adding a new module, remember to add it to
- Modify the corresponding file
test/array.ts
. npm install -g mocha
- Test your change with
mocha --require test/mocha-require.js test/array.ts
- Before committing anything:
npm run lint
and fix any lint errorsnpm run coverage
and fix any missing coverage.npm run doc
and check that it rendered correctly.
Only utility functions that are generically useful will be accepted. Functions that are server-side or client-side specific, or which are only useful in certain domains (e.g. validating emails), belong in different projects.