andy-hanson / tsut

Utilities for TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Use it

Install

npm install --save andy-hanson/tsut#bin # Latest
npm install --save tsut # Stable

Configure

You must use "target": "es6" and "moduleResolution": "node" (or "module": "commonjs") in your tsconfig.json.

Import

import * as u from "tsut";

Call

console.log(u.difference([1, 2, 3], [3, 1])) // Set { 2 }

The utilities

The main modules are:

Module For
option For using Options (`Option = T
function Common higher-order functions.
seq For using Iterables.
asyncSeq For using AsyncIterables.
parallel Like asyncSeq but runs operations in parallel.
async For using Promises and async functions.
array Array helpers.
string For using Strings.
map For using Maps.
set For using Sets.

Other modules are:

Doc Source For
misc Other useful functions.
math For using numbers.
range Ranges of numbers.
tuple For using tuples.
types Easier typeof tests.
reflect Common Proxys.
shims ES-next shims.
builder Builders for data structures. Used internally by seq and asyncSeq.

Why isn't X included?

X Why
Data structures typescript-collections
Random utilities chance
Date utilities moment
More math utilities mathjs

Get Help

File an issue if you have trouble using tsut.

Contribute

  • Fork the repository.
  • npm install and npm 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.
  • 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 errors
    • npm 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.

About

Utilities for TypeScript

License:Other


Languages

Language:TypeScript 99.8%Language:JavaScript 0.2%