JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q31153F
  • License MIT

Control the before and after of running a function, can be used for validation, caching, data mutation and more.

Package Exports

  • fn-lifecycle
  • fn-lifecycle/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fn-lifecycle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

function lifecycle

Control the before and after of running a function, can be used for validation, caching, data mutation and more.

Features

  • Wraps functions to create a lifecycle of before and after
  • Supports TypeScript
  • Can be used for validation, caching, and more
  • Easy to use and integrate into existing projects
  • Provides a flexible and customizable solution for managing function lifecycles

Usage

npm i fn-lifecycle
import { Lifecycle } from "fn-lifecycle";
const lc = new Lifecycle({ name: 1 });
function validate(name) {
  if (!name || (name && name.length < this._.config.name)) {
    throw new Error("name is missing");
  }
}
const addGreet = (name) => `Hi, ${name}`;
const greet = lc.before(validate).after(addGreet).decorate(whatIsMyName);
const myName = "Nir";
await greet(myName);
expect(await greet(myName)).toBe(`Hi, ${myName}`);

check the tests folder for more complete examples.

Contributing

Contributions are always welcome! If you have any ideas or suggestions for how to improve this package, please feel free to open an issue or submit a pull request.