New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lazymacro

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazymacro

macros for javascript

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

lazymacro

macros for javascript

tutorial

  • install

    npm install lazymacro
    
  • require lazymacro in your source code

    require('lazymacro');
    
  • enjoy the macros:

    ["I", "am"].WITH(v => v.push("lazynode.")).WITH(console.log).PIPE(v => v.join(" ")).PIPE(v => console.log(`${v}`))?.PIPE(v => console.log("null safety features can be used together!"));
    

reference

the macros provided in lazymacro

basic macros

  • PIPE: O.PIPE(F) returns F(O)

    "OK".PIPE(v => v + "!") == "OK!"
    
  • WITH: O.WITH(F) runs F(O) and returns O

    ["O", "K"].WITH(v => v.push("!")).PIPE(v => v.join('')) == 'OK!'
    
    "OK".WITH(v => v + "!") == "OK!"
    
  • THEN: O.THEN(F) returns O.then(F)

    await Promise.resolve(5).THEN(v => v + 1) === 6
    
  • WAIT: O.WAIT(F) awaits O.then(F) returns O

    await Promise.resolve(["O", "K"]).WAIT(async v => await new Promise(resolve => setTimeout(() => resolve(v.push("!")), 1000))).THEN(v => v.join('')) == "OK!"
    
  • XMAP: O.XMAP(F) returns an array of F(o, k) where o and k are each element of O

    ["O", "K"].XMAP(v => v.toLowerCase()).PIPE(v => v.join('')) == "ok"
    
    ({ o: "O", k: "K" }).XMAP((v, k) => k + v.toLowerCase()).PIPE(v => v.join('')) == "ookk"
    

lazy macro

LAZY will automatically choose one from PIPE, WITH, THEN and WAIT for you

for O.LAZY(F):

  • WAITis chosen if O is a Promise and O.then(F) is an empty promise
  • THENis chosen if O is a Promise and O.then(F) is not an empty promise
  • WITHis chosen if O is not a Promise and F(O) is an empty promise
  • PIPEis chosen if O is not a Promise and F(O) is not an empty promise

example:

["I", "am"].LAZY(v => { v.push("lazynode.") }).LAZY(v => { console.log(v) }).LAZY(v => v.join(" ")).LAZY(v => { console.log(`${v}`) })?.LAZY(v => console.log("null safety features can be used together!"));

this macros

same as the related basic macro but use this instead of the function paramter

arrow fuction expressions cannot be used as parameter of this macros because this is lost in arrow function expressions

  • PIPETHIS

    "OK".PIPETHIS(function () { return this.toLowerCase() }) == "ok"
    
  • WITHTHIS

    ["O", "K"].WITHTHIS(function () { this.push("!") }).PIPE(v => v.join('')) == 'OK!'
    
  • THENTHIS

    await Promise.resolve("OK").THENTHIS(function () { return this.toLowerCase() }) == "ok"
    
  • WAITTHIS

    await Promise.resolve(["O", "K"]).WAITTHIS(async function () { await new Promise(resolve => setTimeout(resolve, 1000)); this.push("!") }).THEN(v => v.join('')) == "OK!"
    
  • XMAPTHIS

    ["O", "K"].XMAPTHIS(function () { return this.toLowerCase() }).PIPE(v => v.join('')) == "ok"
    

Keywords

macro

FAQs

Package last updated on 17 Oct 2021

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