ts-pipes

Pipe transformation utility functions for TypeScript/JavaScript inspired by Angular Pipes and ngx-pipes

Usage no npm install needed!

<script type="module">
  import tsPipes from 'https://cdn.skypack.dev/ts-pipes';
</script>

README

TS Pipes

GitHub license

Pipe transformation utility functions for TypeScript/JavaScript inspired by Angular Pipes and ngx-pipes

Table of contents

Installation

  1. Use npm to install the package
$ npm install ts-pipes --save 

Date

timeAgo()

Time ago pipe converts date to 'just now', 'X days ago', 'last week', 'X days ago', etc..

Usage:

import Pipe from 'ts-pipes';

const date = Pipe('date');
const now = new Date();
// timeAgo also supports moment.js objects
const lastWeek = moment().subtract(10, 'days');
<span>Updated: { date.timeAgo(now) }</span> <!-- Output: "just now" -->
<span>Updated: { date.timeAgo(lastWeek) }</span> <!-- Output: "last week" -->

String

repeat()

Repeats a string n times

Usage: string | repeat: times: [separator|optional]

<p>{{ 'example' | repeat: 3: '@' }}</p> <!-- Output: "example@example@example" -->

Getting started

Clone this repository and install its dependencies:

$   git clone https://github.com/nikmerlock97/ts-pipes
$   cd ts-pipes
$   npm install

Building

$  npm run build

This builds the library to dist, generating three files:

1. dist/ts-pipes.cjs.js

  • a CommonJS bundle, suitable for use in Node.js, that requires the external dependency
  • corresponds to the "main" field in package.json

2. dist/ts-pipes.esm.js

  • an ES module bundle, suitable for use in other people's libraries and applications, that imports the external dependency
  • corresponds to the "module"field in package.json

3. dist/ts-pipes.umd.js

  • a UMD build, suitable for use in any environment (including the browser, as a <script> tag), that includes the external dependency
  • corresponds to the "browser" field in package.json

npm run dev builds the library, then keeps rebuilding it whenever the source files change using rollup-watch.

Testing

npm test builds the library, then tests it.

License

Forked from rollup-starter-lib.

Inspiration drawn from Angular pipes and ngx-pipes.

MIT License.