A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/andreypopp/sweetify below:

andreypopp/sweetify: Browserify transform for using Sweet.js macros

Browserify transform for using Sweet.js macros.

Install via npm:

and then use with browserify:

% browserify -t sweetify ./mycode.sjs

Sweeten transform kicks in only for files with .sjs extension.

You can use a restricted form of ES6 module import statement to import macros in current module's scope:

import macros from './my-macros.sjs'
import macros from 'some-pkg'

// use everything exported from ./my-macros.sjs or some-pkg node module

As an example, you can see how you can re-use macros already present on npm:

Then create a source file called sparkler-example.sjs:

import macros from 'sparkler/macros';

function myPatterns {
  case 42 => 'The meaning of life'
  case a @ String => 'Hello ' + a
  case [...front, back] => back.concat(front)
  case { foo: 'bar', x, 'y' } => x
  case Email{ user, domain: 'foo.com' } => user
  case (a, b, ...rest) => rest
  case [...{ x, y }] => _.zip(x, y)
  case x @ Number if x > 10 => x
}

This example uses excellent sparkler macros library which implements pattern matching for JavaScript. Just run

% browserify -t sweetify ./sparkler-example.sjs

to produce a JavaScript which you can run in a browser or any other runtime (all pattern matching constructs are compiler into plain JS constructs).


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4