Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #19

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
{
"extends": [
"eslint:recommended"
],

"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},

"parserOptions":{
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},

"globals": {
"document": false,
"navigator": false,
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ node_js:
- node
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
6 changes: 1 addition & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ environment:
# node.js
- nodejs_version: "9.0"
- nodejs_version: "8.0"
- nodejs_version: "7.0"
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "4.0"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
- appveyor-retry npm install
Copy link
Author

@tunnckoCore tunnckoCore Nov 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appveyor-retry is to ensure it install everything properly. Because pretty weirdly some times it fails. Or at least it was that way before year or more.

It will run the command more than once ONLY if it fails (I believe).


# Post-install test scripts.
test_script:
Expand Down
80 changes: 80 additions & 0 deletions examples/refactor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

const AsyncHelpers = require('../index');

async function main() {
const asyncHelpers = new AsyncHelpers();

asyncHelpers.wrapHelper('lower', (val) => val && val.toLowerCase());

console.log('all raw:', asyncHelpers.rawHelpers);
console.log('lower sync:', asyncHelpers.helper('lower'));
console.log('all wrapped:', asyncHelpers.wrappedHelpers);
console.log('lower wrapped:');
console.log(asyncHelpers.wrapHelper('lower'));

console.log('lower non wrapped:');
console.log(asyncHelpers.helper('lower'));

const lower = asyncHelpers.wrapHelper('lower');

console.log('lower wrapped id:', lower('FOO')); // => asyncId
console.log('lower wrapped:', await asyncHelpers.resolveId(lower('FOO')));
// => resolves to 'foo'

asyncHelpers.wrapHelper('lowerAsync', async(str) => str && str.toLowerCase());
const lowerAsync = asyncHelpers.wrapHelper('lowerAsync');

console.log('lowerAsync wrapped id:', lowerAsync('QUX')); // => asyncId
console.log('lowerAsync wrapped:', await asyncHelpers.resolveId(lowerAsync('QUX')));
// => resolves to 'qux'

asyncHelpers.wrapHelper('lowerCb', (str, cb) => cb(null, str && str.toLowerCase()));
const lowerCb = asyncHelpers.wrapHelper('lowerCb');

console.log('lowerCb wrapped id:', lowerCb('GGG')); // => asyncId
console.log('lowerCb wrapped:', await asyncHelpers.resolveId(lowerCb('GGG')));
// => resolves to 'ggg'

// resolveIds (plural)
const str = `foo ${lowerCb('KKK222')} bar ${lowerAsync('QYX')}`;
console.log('resolveIds:', await asyncHelpers.resolveIds(str));
// => foo kkk222 bar qyx

asyncHelpers.wrapHelper('sumAsync', (a, b) => Promise.resolve(a + b));
const sumAsync = asyncHelpers.wrapHelper('sumAsync');
console.log('sumAsync res:', await asyncHelpers.resolveIds(sumAsync(2, 4)));
}

main();

// asyncHelpers.helper('upper', (str) => str && str.toUpperCase());
// asyncHelpers.helper('upperAsync', async(str) => str && str.toUpperCase());
// asyncHelpers.helper('upperAsyncCb', (str, cb) => cb(null, str && str.toUpperCase()));

// asyncHelpers.wrapHelper('lower', (str) => str && str.toLowerCase());
// asyncHelpers.wrapHelper('lowerAsync', async(str) => str && str.toLowerCase());

// const upperWrapped = asyncHelpers.helper('upper');
// const upperNotWrap = asyncHelpers.wrapHelper('upper');

// const lowerWrapped = asyncHelpers.wrapHelper('lower');
// const lowerNotWrap = asyncHelpers.helper('lower');

// console.log(lowerWrapped);
// console.log(lowerNotWrap);

// const allWrapped = asyncHelpers.wrapHelper();

// console.log(allWrapped);
// console.log(lowerNotWrap('ZZZ'));
// asyncHelpers.resolveId(lowerWrapped('FOO')).then(console.log);

// const lowerAsyncId = allWrapped.lowerAsync('FOO');
// console.log(lowerAsyncId);
// asyncHelpers.resolveId(lowerAsyncId).then(console.log);

// const upperAsync = asyncHelpers.wrapHelper('upperAsync');
// console.log(upperAsync('low'));

// asyncHelpers.resolveId(upperAsync('low')).then(console.log);
Loading