forked from olivierkaisin/node-csv-query
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to modern javascript syntax with babel + remove bluebird + remov…
…e event-stream + more flexible parsing & filtering
- Loading branch information
Showing
17 changed files
with
4,199 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": "8.9" | ||
} | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
"extends": "airbnb-base" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
language: "node_js" | ||
node_js: | ||
- "0.10" | ||
- "8.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
|
||
var _lodash = require('lodash'); | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
var Db = function () { | ||
function Db() { | ||
_classCallCheck(this, Db); | ||
|
||
this.rows = []; | ||
} | ||
|
||
_createClass(Db, [{ | ||
key: 'pushRow', | ||
value: function pushRow(row) { | ||
if (!(0, _lodash.isObject)(row)) { | ||
throw new Error('row must be an object'); | ||
} | ||
|
||
this.rows.push(row); | ||
} | ||
|
||
// TODO use the mongo driver syntax (connect, find, ...) | ||
|
||
}, { | ||
key: 'find', | ||
value: function find(predicate) { | ||
return Promise.resolve((0, _lodash.filter)(this.rows, predicate)); | ||
} | ||
}, { | ||
key: 'findOne', | ||
value: function findOne(predicate) { | ||
return Promise.resolve((0, _lodash.find)(this.rows, predicate)); | ||
} | ||
}]); | ||
|
||
return Db; | ||
}(); | ||
|
||
exports.default = Db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _csvParse = require('csv-parse'); | ||
|
||
var _csvParse2 = _interopRequireDefault(_csvParse); | ||
|
||
var _fs = require('fs'); | ||
|
||
var _fs2 = _interopRequireDefault(_fs); | ||
|
||
var _lodash = require('lodash'); | ||
|
||
var _db = require('./db'); | ||
|
||
var _db2 = _interopRequireDefault(_db); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function createFromFile(filePath) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
|
||
var db = new _db2.default(); | ||
|
||
var parser = (0, _csvParse2.default)((0, _lodash.merge)(options, { columns: true })); | ||
|
||
return new Promise(function (resolve, reject) { | ||
_fs2.default.createReadStream(filePath).pipe(parser).on('data', db.pushRow.bind(db)).on('error', reject).on('finish', function () { | ||
return resolve(db); | ||
}); | ||
}); | ||
} | ||
|
||
exports.default = createFromFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
"use strict"; | ||
#!/usr/bin/env node | ||
|
||
require('babel-polyfill'); | ||
require('babel-register'); | ||
|
||
module.exports = require("./src/loader"); | ||
module.exports = require('./src/loader.js'); |
Oops, something went wrong.