Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

advice-function

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

advice-function

Implementation of Advice pattern for functional programing

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Advice Function

This is a basic implementation of Advice pattern for functional programing.

Before and After

Both functions called with the same arguments of the main functions. These functions don`t change the value of arguments or result value of main function.

Example

import advice from 'advice-function'

// hello world
const greeting = (pattern) => (name) => (pattern.replace('{name}', name))
const hello = advice(greeting('Hello {name}'))
  .before((name) => console.log('show wellcome message to', name))
  .after((name) => console.log(name, 'is greeted'))

hello('world')

Arround

This decorator is the best of decorators, because we can use to multiple porpuse (replace arguments, call to another methods after and before to call main function, ....)

If You don´t set any function to Arround list, main function is called.

Example

import advice from 'advice-function'

// hello world
const greeting = (pattern) => (name) => (pattern.replace('{name}', name))
const hello = advice(greeting('Hello {name}'))
  .arround((mainFn) => (name) => {
    console.log('show wellcome message to', name)
    mainFn(name.toUpperCase())
    console.log(name, 'is greeted')
  })

hello('world')

License

currency-format is licensed under the MIT License.

Keywords

FAQs

Package last updated on 31 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc