Skip to content

pd4d10/fluent-interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fluent-interface

npm

Easily build fluent interface in JavaScript.

Usage

const add = (t, n) => {
  t.value += n;
  return t;
};

const subtract = (t, n) => {
  t.value -= n;
  return t;
};

const multiply = (t, n) => {
  t.value *= n;
  return t;
};

const divide = (t, n) => {
  t.value /= n;
  return t;
};

const calculator = fi(
  { value: 0 },
  {
    add,
    subtract,
    multiply,
    divide,
  }
);

const result = calculator //
  .add(10)
  .subtract(5)
  .multiply(4)
  .divide(2);

console.log(result.value); // 10
// (0 + 10 - 5) * 4 / 2

License

MIT

About

Easily build fluent interface in JavaScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published