merge-timerange
Advanced tools
Comparing version 0.2.1 to 1.0.0
38
index.js
'use strict'; | ||
require('esfunctional'); | ||
/* global spawn, catchify, promisify, | ||
values, clone, cloneDeep, forEach, extend, | ||
values, clone, cloneDeep, extend, | ||
zipObject, fromPairs, pick, omit, groupBy, fill, | ||
@@ -84,3 +85,3 @@ mapValues, reduce, map, filter, flatten */ | ||
// } | ||
S.mergeTimeranges = (arg) => { | ||
S.mergeTimeranges = function*(arg) { | ||
@@ -144,5 +145,6 @@ //jshint maxcomplexity: 19 | ||
if (needMerge && arg.prop.check) arg.prop.check [forEach]((prop) => needMerge = ( | ||
from[prop] === to[prop] | ||
)); | ||
if (needMerge && arg.prop.check) for (let prop of arg.prop.check) { | ||
needMerge = from[prop] === to[prop]; | ||
if (!needMerge) break; | ||
} | ||
@@ -205,2 +207,3 @@ if (needMerge) { | ||
// nosort: Boolean, | ||
// nocheck: Boolean, | ||
// get: Boolean, | ||
@@ -210,3 +213,3 @@ // remove: Boolean, | ||
// } | ||
S.normalize = (arg) => spawn(function*() { | ||
S.normalize = function*(arg) { | ||
let maxIntervalMsec = arg.maxInterval ? arg.maxInterval * 1000 : 0; | ||
@@ -230,3 +233,3 @@ | ||
//jshint maxcomplexity: 8 | ||
//jshint maxcomplexity: 12 | ||
@@ -257,5 +260,16 @@ let starting = yield arg.Model.findOne( | ||
if (!arg.nosort) source.sort((a, b) => a.start - b.start); | ||
if (source.length) { | ||
if (!arg.nosort) source.sort((a, b) => a.start - b.start); | ||
if (!arg.get) S.mergeTimeranges({ | ||
if (!arg.nocheck) { | ||
let endpr = source[0].end; | ||
for (let i = 1; i < source.length; i++) { | ||
if (source[i].start < endpr) throw ['rangeCheckFailed']; | ||
endpr = source[i].end; | ||
} | ||
} | ||
} | ||
if (!arg.get) yield* S.mergeTimeranges({ | ||
maxInterval: arg.maxInterval, | ||
@@ -297,3 +311,3 @@ from: source, | ||
return true; | ||
}); | ||
}; | ||
@@ -313,3 +327,3 @@ // { | ||
// } | ||
S.save = (arg) => spawn(function*() { | ||
S.save = function*(arg) { | ||
let fields = arg.prop [values]() [flatten]() [map](prop => prop.split('.')[0]); | ||
@@ -331,2 +345,2 @@ fields.push('start', 'end', 'time'); | ||
return !tasks.length ? [] : yield Promise.all(tasks); | ||
}); | ||
}; |
56
lint.js
@@ -0,36 +1,50 @@ | ||
'use strict'; | ||
require('esfunctional'); | ||
// code linter | ||
// use: `node lint` | ||
var child = require('child_process'); | ||
var chalk = require('chalk'); | ||
/* global spawn, main, finalizer, halt, errstack, out, chalk */ | ||
var paths = ['index.js', 'test']; | ||
let child = require('child_process'); | ||
function exec(bin, args) { | ||
return child.spawnSync(bin, args, {stdio: [process.stdin, process.stdout, process.stderr], cwd: __dirname}).status; | ||
} | ||
let paths = ['index.js', 'lint.js', 'test']; | ||
process.exit( | ||
( | ||
let S = module.exports; | ||
console.log(chalk.bold.yellow('JS CodeStyle'), chalk.gray('code formatting')), | ||
S.exec = (bin, args) => spawn(function*() { | ||
let lintingFailed = new Error('Linting failed') [errstack](5, 1); | ||
let proc = child.spawn(bin, args, {stdio: 'inherit', cwd: __dirname}); | ||
S.currentProc = proc; | ||
let evt = yield proc [event](['exit', 'close'], ['error', 'unhandledException']); | ||
S.currentProc = null; | ||
if (evt.data) throw lintingFailed; | ||
}); | ||
exec('node_modules/.bin/jscs', ['-c', '.jscsrc'].concat(paths)) | ||
S.init = spawn(function*() { | ||
out.setNs('lint'); | ||
) || (console.log(chalk.bold.green('\n+ Code Style OK\n')), 0) || ( | ||
out.info(chalk.bold.yellow('JS CodeStyle'), chalk.gray('code formatting')); | ||
yield S.exec('node_modules/.bin/jscs', ['-c', '.jscsrc'].concat(paths)); | ||
console.log(chalk.bold.green('\n+ Code Style OK\n')); | ||
console.log(chalk.bold.yellow('JSHint'), chalk.gray('code syntax')), | ||
out.info(chalk.bold.yellow('JSHint'), chalk.gray('code syntax')); | ||
exec('node_modules/.bin/jshint', [ | ||
'-c', '.jshintrc', | ||
'--reporter', 'node_modules/jshint-stylish-ex/stylish.js' | ||
].concat(paths)) | ||
yield S.exec('node_modules/.bin/jshint', [ | ||
'-c', '.jshintrc', | ||
'--reporter', 'node_modules/jshint-stylish-ex/stylish.js' | ||
].concat(paths)); | ||
) || ( | ||
out.info(chalk.bold.yellow('JS Inspect'), chalk.gray('copy & paste detector')); | ||
yield S.exec('node_modules/.bin/jsinspect', [].concat(paths)); | ||
console.log(chalk.bold.yellow('JS Inspect'), chalk.gray('copy & paste detector')), | ||
console.log(chalk.bold.green('\n===== All Linters Succeeded =====')); | ||
}); | ||
exec('node_modules/.bin/jsinspect', [].concat(paths)) | ||
S.exit = () => spawn(function() { | ||
S.init [halt](); | ||
if (S.currentProc) S.currentProc.kill('SIGTERM'); | ||
}); | ||
) || (console.log(chalk.bold.green('\n===== All Linters Succeeded =====')), 0) | ||
); | ||
module [main](S.init); | ||
module [finalizer](S.exit); |
{ | ||
"name": "merge-timerange", | ||
"version": "0.2.1", | ||
"version": "1.0.0", | ||
"description": "Merge time ranges", | ||
@@ -26,9 +26,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"esfunctional": "1.8.4" | ||
}, | ||
"devDependencies": { | ||
"jscs": "2.5.1", | ||
"jshint": "2.8.0", | ||
"jscs": "3.0.6", | ||
"jshint": "2.9.2", | ||
"jshint-stylish-ex": "0.2.0", | ||
"jsinspect": "0.7.1" | ||
"jsinspect": "0.8.0" | ||
} | ||
} |
'use strict'; | ||
/* global T, spawn, test */ | ||
/* global T, spawn, test, chalk */ | ||
let Merge = require('..'); | ||
let chalk = require('chalk'); | ||
@@ -70,3 +69,3 @@ module.exports = spawn(function*() { | ||
yield Merge.mergeTimeranges({ | ||
yield* Merge.mergeTimeranges({ | ||
from: T.from1, | ||
@@ -77,3 +76,3 @@ to: T.merged, | ||
yield Merge.mergeTimeranges({ | ||
yield* Merge.mergeTimeranges({ | ||
from: T.from2, | ||
@@ -80,0 +79,0 @@ to: T.merged, |
'use strict'; | ||
/* global T, spawn, test */ | ||
/* global T, spawn, test, chalk */ | ||
let Merge = require('..'); | ||
let chalk = require('chalk'); | ||
@@ -13,3 +12,3 @@ module.exports = spawn(function*() { | ||
yield Merge.mergeTimeranges({ | ||
yield* Merge.mergeTimeranges({ | ||
from: T.from1, | ||
@@ -20,3 +19,3 @@ to: T.removed, | ||
yield Merge.mergeTimeranges({ | ||
yield* Merge.mergeTimeranges({ | ||
from: T.from2, | ||
@@ -23,0 +22,0 @@ to: T.removed, |
'use strict'; | ||
/* global T, spawn, test, | ||
cloneDeep, forEach, extend */ | ||
cloneDeep, forEach, extend, chalk */ | ||
let Merge = require('..'); | ||
let chalk = require('chalk'); | ||
@@ -26,9 +25,13 @@ module.exports = spawn(function*() { | ||
return {sort: function(sort) { | ||
sort [test]('Sort must match', {head: 1, end: 1}); | ||
return { | ||
sort: function(sort) { | ||
sort [test]('Sort must match', {head: 1, end: 1}); | ||
return {exec: () => new Promise((resolve) => { | ||
resolve({start: new Date('2015-01-01T10:00:00Z')}); | ||
})}; | ||
}}; | ||
return { | ||
exec: () => new Promise((resolve) => { | ||
resolve({start: new Date('2015-01-01T10:00:00Z')}); | ||
}) | ||
}; | ||
} | ||
}; | ||
}, | ||
@@ -50,11 +53,15 @@ | ||
return {sort: function(sort) { | ||
sort [test]('Sort must match', {head: 1, start: 1}); | ||
return { | ||
sort: function(sort) { | ||
sort [test]('Sort must match', {head: 1, start: 1}); | ||
return {exec: () => new Promise((resolve) => { | ||
resolve(T.from1 [cloneDeep]() [forEach]((item) => { | ||
item [extend]({toObject: function() {return this;}}); | ||
})); | ||
})}; | ||
}}; | ||
return { | ||
exec: () => new Promise((resolve) => { | ||
resolve(T.from1 [cloneDeep]() [forEach]((item) => { | ||
item [extend]({toObject: function() {return this;}}); | ||
})); | ||
}) | ||
}; | ||
} | ||
}; | ||
} | ||
@@ -69,3 +76,3 @@ }; | ||
yield Merge.normalize(merge1); | ||
yield* Merge.normalize(merge1); | ||
@@ -138,3 +145,3 @@ merge1.inserts [test]('merged inserts should match', [ | ||
yield Merge.normalize(merge2); | ||
yield* Merge.normalize(merge2); | ||
}); |
'use strict'; | ||
/* global T, spawn, test, | ||
cloneDeep, pick */ | ||
cloneDeep, pick, chalk */ | ||
let Merge = require('..'); | ||
let chalk = require('chalk'); | ||
@@ -19,3 +18,3 @@ module.exports = spawn(function*() { | ||
yield Merge.normalize(merge2); | ||
yield* Merge.normalize(merge2); | ||
@@ -46,3 +45,3 @@ merge2.insertsShouldBe = T.removed.slice(1).concat(undefined); | ||
yield Merge.save(merge2); | ||
yield* Merge.save(merge2); | ||
}); |
'use strict'; | ||
require('esfunctional'); | ||
/* global spawn, thena, catcha */ | ||
/* global spawn, thena, catcha, chalk */ | ||
let chalk = require('chalk'); | ||
global.T = {}; | ||
@@ -9,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
24669
15
717
0
1
4
+ Addedesfunctional@1.8.4
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedboolbase@1.0.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcss-select@4.3.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-converter@0.2.0(transitive)
+ Addeddom-serializer@1.4.1(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomhandler@4.3.1(transitive)
+ Addeddomutils@2.8.0(transitive)
+ Addedentities@2.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesfunctional@1.8.4(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhtmlparser2@6.1.0(transitive)
+ Addedlodash@4.13.14.17.21(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedpretty-error@2.0.0(transitive)
+ Addedrenderkid@2.0.7(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedutila@0.4.0(transitive)