Skip to content

Commit

Permalink
Use prettier for code formatting
Browse files Browse the repository at this point in the history
PR-URL: #402
  • Loading branch information
JuliaGerasymenko authored and nechaido committed Jan 21, 2019
1 parent 42adb96 commit ada7be7
Show file tree
Hide file tree
Showing 53 changed files with 784 additions and 574 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
extends: 'metarhia'
extends:
- metarhia
- plugin:prettier/recommended
plugins:
- prettier
rules:
prettier/prettier: error
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
README.md
dist
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
24 changes: 14 additions & 10 deletions lib/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
// promise <Promise>
// callback <Function>
const promiseToCallbackLast = promise => callback => {
promise.then(value => {
callback(null, value);
}, reason => {
callback(reason);
});
promise.then(
value => {
callback(null, value);
},
reason => {
callback(reason);
}
);
};

// Convert Promise-returning to callback-last / error-first contract
Expand Down Expand Up @@ -42,12 +45,13 @@ const asyncify = fn => (...args) => {
// fn <Function> callback-last function
//
// Returns: <Function> Promise-returning function
const promisify = fn => (...args) => new Promise((resolve, reject) => {
fn(...args, (err, data) => {
if (err) reject(err);
else resolve(data);
const promisify = fn => (...args) =>
new Promise((resolve, reject) => {
fn(...args, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
});

// Convert sync function to Promise object
// fn <Function> regular synchronous function
Expand Down
2 changes: 1 addition & 1 deletion lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const asyncMap = (items, fn, options = {}, done) => {
const countNumber = () => {
const loopTime = Date.now() - begin;
const itemTime = sum / count;
const necessaryNumber = ratio * loopTime / itemTime;
const necessaryNumber = (ratio * loopTime) / itemTime;
return Math.max(necessaryNumber, min);
};

Expand Down
11 changes: 6 additions & 5 deletions lib/async-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AsyncIterator {

async every(predicate, thisArg) {
for await (const value of this) {
if (!await predicate.call(thisArg, value)) {
if (!(await predicate.call(thisArg, value))) {
return false;
}
}
Expand Down Expand Up @@ -256,8 +256,9 @@ class FlatIterator extends AsyncIterator {
return next;
}

this.stack[++this.currentDepth] = next.value[Symbol.asyncIterator] ?
next.value[Symbol.asyncIterator]() : next.value[Symbol.iterator]();
this.stack[++this.currentDepth] = next.value[Symbol.asyncIterator]
? next.value[Symbol.asyncIterator]()
: next.value[Symbol.iterator]();
}

return { done: true, value: undefined };
Expand Down Expand Up @@ -324,7 +325,7 @@ class TakeWhileIterator extends AsyncIterator {
async next() {
if (this.done) return { done: true, value: undefined };
const next = await this.base.next();
if (!next.done && await this.predicate.call(this.thisArg, next.value)) {
if (!next.done && (await this.predicate.call(this.thisArg, next.value))) {
return next;
}
this.done = true;
Expand Down Expand Up @@ -420,7 +421,7 @@ class ThrottleIterator extends AsyncIterator {
await timeout();
const loopTime = Date.now() - this.begin;

const number = Math.max(this.ratio * loopTime / itemTime, this.min);
const number = Math.max((this.ratio * loopTime) / itemTime, this.min);

this.iterMax = Math.round(number) + this.count;

Expand Down
18 changes: 12 additions & 6 deletions lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ const { map, filter, reduce, each, series, find } = require('./array');

const async = op => {
switch (op) {
case 'map': return map;
case 'filter': return filter;
case 'reduce': return reduce;
case 'each': return each;
case 'series': return series;
case 'find': return find;
case 'map':
return map;
case 'filter':
return filter;
case 'reduce':
return reduce;
case 'each':
return each;
case 'series':
return series;
case 'find':
return find;
}
return (items, fn, callback) => {
callback(null, items.slice());
Expand Down
9 changes: 3 additions & 6 deletions lib/collector.prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,10 @@ KeyCollector.prototype.collect = function(key, data) {
}
};

KeyCollector.prototype.stop = function() {
};
KeyCollector.prototype.stop = function() {};

KeyCollector.prototype.pause = function() {
};
KeyCollector.prototype.pause = function() {};

KeyCollector.prototype.resume = function() {
};
KeyCollector.prototype.resume = function() {};

module.exports = { DataCollector, KeyCollector };
10 changes: 6 additions & 4 deletions lib/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const { each } = require('./array');
// callback - <Function>, on done, err-first
const firstOf = (fns, callback) => {
const done = common.once(callback);
each(fns, (f, iterCb) => f((...args) => {
done(...args);
iterCb(...args);
}));
each(fns, (f, iterCb) =>
f((...args) => {
done(...args);
iterCb(...args);
})
);
};

// Parallel execution
Expand Down
18 changes: 8 additions & 10 deletions lib/fp.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ const of = (...args) => asAsync(callback => callback(null, ...args));
// Monoid m => a -> a -> a
// fn1 - <Function>
// fn2 - <Function>
const concat = (fn1, fn2) => toAsync(
(args1, callback) => fn1(...args1, (err, ...args2) => {
if (err !== null) callback(err);
else fn2(...args2, callback);
})
);
const concat = (fn1, fn2) =>
toAsync((args1, callback) =>
fn1(...args1, (err, ...args2) => {
if (err !== null) callback(err);
else fn2(...args2, callback);
})
);

// Functor f => (a -> b) -> f a -> f b
// fn1 - <Function>
Expand All @@ -51,10 +52,7 @@ const fmap = (fn1, f) => {
// Applicative f => f (a -> b) -> f a -> f b
// fn - <Function>
// funcA - <Function>
const ap = (
fn,
funcA
) => concat(funcA, (f, callback) => fmap(fn, f)(callback));
const ap = (fn, funcA) => concat(funcA, (f, callback) => fmap(fn, f)(callback));

asyncChainMethods = { fmap, ap, concat };

Expand Down
7 changes: 4 additions & 3 deletions lib/poolify.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const poolified = Symbol('poolified');

const mixFlag = { [poolified]: true };

const duplicate = (factory, n) => Array
.from({ length: n }, factory)
.map(instance => Object.assign(instance, mixFlag));
const duplicate = (factory, n) =>
Array.from({ length: n }, factory).map(instance =>
Object.assign(instance, mixFlag)
);

const provide = callback => item => {
setImmediate(() => {
Expand Down
24 changes: 5 additions & 19 deletions lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ Queue.prototype.wait = function(msec) {
// default: 1000 msec
//
// Returns: <this>
Queue.prototype.throttle = function(
count,
interval = 1000
) {
Queue.prototype.throttle = function(count, interval = 1000) {
this.throttleCount = count;
this.throttleInterval = interval;
return this;
Expand All @@ -57,11 +54,7 @@ Queue.prototype.throttle = function(
// priority - <number>, optional
//
// Returns: <this>
Queue.prototype.add = function(
item,
factor = 0,
priority = 0
) {
Queue.prototype.add = function(item, factor = 0, priority = 0) {
if (this.priorityMode && !this.roundRobinMode) {
priority = factor;
factor = 0;
Expand Down Expand Up @@ -187,10 +180,7 @@ Queue.prototype.clear = function() {
// onTimeout - <Function>
//
// Returns: <this>
Queue.prototype.timeout = function(
msec,
onTimeout = null
) {
Queue.prototype.timeout = function(msec, onTimeout = null) {
this.processTimeout = msec;
if (onTimeout) this.onTimeout = onTimeout;
return this;
Expand Down Expand Up @@ -270,9 +260,7 @@ Queue.prototype.lifo = function() {
// disable priority mode
//
// Returns: <this>
Queue.prototype.priority = function(
flag = true
) {
Queue.prototype.priority = function(flag = true) {
this.priorityMode = flag;
return this;
};
Expand All @@ -282,9 +270,7 @@ Queue.prototype.priority = function(
// disable roundRobin mode
//
// Returns: <this>
Queue.prototype.roundRobin = function(
flag = true
) {
Queue.prototype.roundRobin = function(flag = true) {
this.roundRobinMode = flag;
return this;
};
Expand Down
6 changes: 3 additions & 3 deletions lib/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const throttle = (timeout, fn, ...args) => {
let timer;
let wait = false;

const execute = args ?
(...pars) => (pars ? fn(...args, ...pars) : fn(...args)) :
(...pars) => (pars ? fn(...pars) : fn());
const execute = args
? (...pars) => (pars ? fn(...args, ...pars) : fn(...args))
: (...pars) => (pars ? fn(...pars) : fn());

const delayed = (...pars) => {
timer = undefined;
Expand Down
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"perf": "tests/load/run.sh",
"lint": "eslint .",
"docs": "metaschema ./metasync.js",
"fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" .eslintrc .prettierrc",
"build": "babel metasync.js -d dist && babel lib -d dist/lib",
"prepublish": "npm run -s build"
},
Expand All @@ -54,8 +55,11 @@
"@babel/preset-env": "^7.2.0",
"eslint": "^5.9.0",
"eslint-config-metarhia": "^6.1.0",
"eslint-config-prettier": "^3.4.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.1",
"metaschema": "^0.0.26",
"metatests": "^0.3.0"
"metatests": "^0.3.0",
"prettier": "1.15.3"
}
}
Loading

0 comments on commit ada7be7

Please sign in to comment.