in-js

Add a keyword, in?, to JavaScript

Usage no npm install needed!

<script type="module">
  import inJs from 'https://cdn.skypack.dev/in-js';
</script>

README

in-js

in-js is a sweet.js macro for JavaScript which adds a keyword, in?, to the language.

Examples

The file examples.js in this repo contains a few examples. To run that file, run make run-examples in the root of this repo.

var x = 1, y = [1, 2, 3];

if (x in? y) {
  console.log("1 is in the list [1, 2, 3]");
}

// 1 is in the list [1, 2, 3]
var frameworks = [
  {language: "ruby", "name": "rails"},
  {language: "clojure", name: "compojure"},
  {language: "javascript", name: "koa"},
  {language: "python", name: "django"},
];

var filtered = frameworks.filter(function(framework){
  return framework.language in? ['ruby', 'javascript'];
});

console.log(filtered);

/*
[ { language: 'ruby', name: 'rails' },
  { language: 'javascript', name: 'koa' } ]
*/

Tests

make test

License

MIT