Skip to content

Esy is a new JS preprocessor allows you to use custom block structures.

License

Notifications You must be signed in to change notification settings

Slye3D/esy-language

Repository files navigation

Esy

NPM

CircleCI npm version downloads dependencies license Join the chat at https://gitter.im/Slye-team/esy-language

Esy Logo

Esy is a new JS preprocessor allows you to use custom block structures.

What does it mean?

Right now in JavaScript and many other languages that support the block structure, you're only able to use some predefined structures like:

  1. if (){...}
  2. for (){...}
  3. while (){...}
  4. do {...} while();
  5. switch (){...}
  6. else {...}
  7. try {...}
  8. catch (){...}
  9. finally (){...}
  10. etc...

Those are all familiar structures to you, but have you ever thought about the following structure?

timeout 200 {
   console.log("Hello World!");
}

Certainly, it's easier than what we have in JS right now:

setTimeout(function() {
   console.log("Hello World!");
}, 200);

Or even with arrow functions:

 setTimeout(() => {
    console.log("Hello World!");
 }, 200);

That why Esy comes from Easy

Install

You can install this package globally by running:

npm install esy-language -g

but if you're interested in the core API and wants to use it in your own package just run:

npm install esy-language --save

Example

After installing the Esy, save this file as ex.esy

// Cache sum for 500ms
cache 500 sum(a,b){
	console.log('Computing...');
	return a+b;
} key (c,d){
	// We don't care about numbers order in sum function (a+b=b+a)
	return [c, d].sort();
}

// Compute 5+7 once
console.log(sum(5,7))

// Load theme from cache without computing
console.log(sum(5,7))
console.log(sum(7,5))

// Wait 100ms more than cache's lifetime.
timeout 600{
	// It should compute 5+7 again
	console.log(sum(7,5))
}

and then cd to the directory that your file is and run this command to run program:

esy ex.esy

for saving result to a file run:

esy compile ex.esy -s

Docs

Read official docs for more details.

Testing

To run tests just run:

git clone https://github.com/Slye-team/esy-language.git
cd esy-language
npm run test