1.0.1 • Published 2 years ago

@chadams/js-pipes v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

js-pipes

Angular like pipes anywhere

Install

$ npm i @chadams/js-pipes

Usage

import PipesEngine from "js-pipes";

const piper = PipesEngine();

piper({ name: "test string" }, "${name}"); // 'test string'

built in transforms

uppercase

piper({ name: "test string" }, "${name|uppercase}"); // 'TEST STRING'

date

using dayjs

piper({ start: "2021-03-26T15:32:37-04:00" }, "${start|date:'MM/DD/YYYY'}"); // '03/26/2021'
piper({ start: "2021-03-26T15:32:37-04:00" }, "${start|date:'llll'}"); // 'Fri, Mar 26, 2021 3:32 PM'

switch

piper({ yes: true }, "${yes|sw:'happy','sad'}"); // happy
piper({ yes: false }, "${yes|sw:'happy','sad'}"); // sad

currency

piper({ amount: 1223.33 }, "${amount|currency}"); // '$1,223.33'

deeply nested data works

piper({ user: [{ name: "test string" }] }, "${user[0].name|uppercase}"); // 'TEST STRING'

make your own transforms

const calendar = () => (dateStr) => {
  return dayjs().calendar(dayjs(dateStr));
};

const piper = PipesEngine({
  calendar
};
});

piper({ name: 'test string' }, '${name}'); // 'test string'

License

MIT