unless-macro

Proper usage of Ruby's unless in JavaScript

Usage no npm install needed!

<script type="module">
  import unlessMacro from 'https://cdn.skypack.dev/unless-macro';
</script>

README

unless

Proper usage of Ruby's unless in JavaScript

Examples

unless (foo) {
  bar()
  baz()
}

expands to

if (!foo) {
  function () {
    bar()
    baz()
  }()
}
return foo unless (bar)

expands to

if (!bar) {
  return foo
}
foo unless (bar)

expands to

if (!bar) {
  function () {
    foo
  }()
}

Installation

  1. $ npm install --save unless-macro.

  2. Load using sweetjs-loader like,

// webpack.config.js
module.exports = {
  cache: true,
  entry: 'app.js',
  output: {
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      test: /\.js$/, loader: 'sweetjs?modules[]=unless-macro/unless.sjs'
    }]
  }
};

to expand the macro at build time.