Angular like pipes anywhere
$ npm i @chadams/js-pipesimport PipesEngine from "js-pipes";
const piper = PipesEngine();
piper({ name: "test string" }, "${name}"); // 'test string'piper({ name: "test string" }, "${name|uppercase}"); // 'TEST STRING'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'piper({ yes: true }, "${yes|sw:'happy','sad'}"); // happy
piper({ yes: false }, "${yes|sw:'happy','sad'}"); // sadpiper({ amount: 1223.33 }, "${amount|currency}"); // '$1,223.33'piper({ user: [{ name: "test string" }] }, "${user[0].name|uppercase}"); // 'TEST STRING'const calendar = () => (dateStr) => {
return dayjs().calendar(dayjs(dateStr));
};
const piper = PipesEngine({
calendar
};
});
piper({ name: 'test string' }, '${name}'); // 'test string'