Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datapackage-query

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datapackage-query - npm Package Compare versions

Comparing version 0.1.0 to 0.1.3

.npmignore

21

index.js

@@ -21,5 +21,6 @@ var fs = require("fs");

// Load Data & Parse
Query.Twirl = function(data_path, resource, callback) {
Query.Twirl = function(data_path, resource, args, callback) {
console.log('Twirl CSV resource: ' + data_path + '/' + resource.path);
console.log('Twirl CSV resource: ' + data_path + '/' + resource.path + ' with args: ');
console.log(args);

@@ -33,2 +34,5 @@ Query.Recipe.readManuscript(data_path + '/' + resource.path)

// Sanitize Args
var allowed_args= _.union(fields, ['search']);
// Turn CSV Data into array, then map + add to output

@@ -43,10 +47,7 @@ csv.parse(csv_data, function(err, csv_object) {

_.each(csv_object, function(csv_line, key) {
var json_line = _.object(fields, csv_line);
// NOTE: Used to then do filtering here for performance reasons
// Will be moved elsewhere, but should be benchmarked
// Might want to put it back here to spare overhead of 2x loops
// Query.magickData(data, resource.schema, Query.options.date);
csv_to_json.push(_.object(fields, csv_line));
if (Query.Filter(resource.schema, allowed_args, args, json_line)) {
csv_to_json.push(json_line);
}
});

@@ -82,2 +83,2 @@

module.exports = Query;
module.exports = Query;
var _ = require('underscore');
var moment = require('moment');
var FilterDate = {};
var FilterDate = function(date) {
var date_filter = 'none';
if (date !== undefined) {
// TODO: would it be easier to just use moment.js for this?
var is_date_full = /[0-9]{4}-[0-9]{2}-[0-9]{2}/;
var is_date_year_month = /[0-9]{4}-[0-9]{2}/;
var is_date_month_day = /[0-9]{2}-[0-9]{2}/;
var is_date_year = /[0-9]{4}/;
var is_week = /week/;
var is_month = /month/;
var is_today = /today/;
if (is_week.exec(date)) {
date_type = 'this_week';
} else if (is_today.exec(date)) {
date_type = 'today';
} else if (is_month.exec(date)) {
date_type = 'this_month';
} else if (is_date_full.exec(date)) {
date_type = 'full';
} else if (is_date_year_month.exec(date)) {
date_type = 'year_month';
} else if (is_date_month_day.exec(date)) {
date_type = 'month_day';
} else if (is_date_year.exec(date)) {
date_type = 'year';
} else {
date_type = 'month';
}
}
return date_type;
};
FilterDate.full = function(date, dateArg) {

@@ -7,0 +43,0 @@

@@ -8,54 +8,52 @@ var _ = require('underscore');

Filter = function(schema_fields, data) {
Filter = function(schema, allowed_args, args, line) {
// Filter by Date / Type
var date_filter = 'none';
// Set All as Failing
var check_date = [];
var check_trim = [];
var check_search = [];
if (date !== undefined) {
// Check Schema item for arg to determine "type" of
// filters which parser is able to perform
_.each(args, function(arg, key) {
// TODO: would it be easier to just use moment.js for this?
var is_date_full = /[0-9]{4}-[0-9]{2}-[0-9]{2}/;
var is_date_year_month = /[0-9]{4}-[0-9]{2}/;
var is_date_month_day = /[0-9]{2}-[0-9]{2}/;
var is_date_year = /[0-9]{4}/;
var is_week = /week/;
var is_month = /month/;
var is_today = /today/;
if (key == 'search') {
if (is_week.exec(date)) {
date_filter = 'this_week';
} else if (is_today.exec(date)) {
date_filter = 'today';
} else if (is_month.exec(date)) {
date_filter = 'this_month';
} else if (is_date_full.exec(date)) {
date_filter = 'full';
} else if (is_date_year_month.exec(date)) {
date_filter = 'year_month';
} else if (is_date_month_day.exec(date)) {
date_filter = 'month_day';
} else if (is_date_year.exec(date)) {
date_filter = 'year';
} else {
date_filter = 'month';
}
check_search.push(FilterSearch(arg, line));
}
} else if (_.indexOf(allowed_args, key) > -1) {
var field = _.findWhere(schema.fields, { name: key });
// Filter Date & Trim
var check_date = Conjuror.Date[date_filter](parts[0], date);
var check_trim = Conjuror.Trim(Conjuror.options.trim, parts);
var check_search = Conjuror.Search(parts, Conjuror.options.search);
// Filter Date
if (field.type == 'date') {
// var date_filter = FilterDate.Determine(date);
// var check_date = FilterDate[date_filter](parts[0], date);
var date_type = FilterDate(arg);
check_date = FilterDate[date_type](data, arg);
} else if (field.type == 'string') {
check_trim.push(FilterTrim(key, arg, line));
} else if (field.type == 'number') {
console.log('filtering by number not supported yet')
// Should offer things like "before:2015" or "after:2013"
} else {
console.log('field is not "search" and not defined in schema')
}
}
});
// Does Item Meet Filter (date, trim)
if (_.indexOf([check_date, check_trim, check_search], false) === -1) {
var item_output = Conjuror.murmurLineToSchema(line, schema);
increment_output(item_output);
if (_.indexOf(check_trim, false) === -1 &&
_.indexOf(check_search, false) === -1) {
return true;
} else {
return false;
}
return outputs;
}
module.exports = Filter;
module.exports = Filter;

@@ -0,18 +1,15 @@

var _ = require('underscore');
FilterSearch = function(parts, term) {
if (term !== undefined) {
// FIXME: ugly duplication of trim https://github.com/bnvk/Conjuror/issues/35
var part = parts[2].toLowerCase();
var search = term.toLowerCase();
if (part.indexOf(search) > -1) {
//console.log('description: ' + part + ' | contains: ' + search);
return true;
} else {
return false;
}
FilterSearch = function(term, line) {
var line_string = _.values(line).join(' ');
var line_ready = line_string.toLowerCase();
if (line_ready.indexOf(term.toLowerCase()) > -1) {
return true;
} else {
return true;
return false;
}
};
module.exports = FilterSearch;
module.exports = FilterSearch;
var _ = require('underscore');
FilterTrim = function(trim, parts) {
if (trim !== undefined) {
var part = parts[3].trim();
if (_.indexOf(trim, part) > -1) {
//console.log('client: ' + part + ' matches: ' + args.options.trim);
return true;
} else {
return false;
}
FilterTrim = function(key, arg, line) {
if (line[key] == arg) {
return true;
} else {
return true;
return false;
}
};
module.exports = FilterTrim;
module.exports = FilterTrim;
{
"name": "datapackage-query",
"version": "0.1.0",
"version": "0.1.3",
"description": "Opens datapackage.json and resource.csv files and performs simple queries on the contents",

@@ -25,8 +25,25 @@ "main": "index.js",

],
"author": "Brennan Novak",
"author": {
"name": "Brennan Novak"
},
"license": "MIT",
"dependencies": {
"csv": "^0.4.1",
"es6-promise": "^2.0.1",
"fs": "*",
"moment": "^2.9.0",
"underscore": "*"
},
"bugs": {
"url": "https://github.com/bnvk/datapackage-query/issues"
},
"homepage": "https://github.com/bnvk/datapackage-query#readme"
"homepage": "https://github.com/bnvk/datapackage-query#readme",
"readme": "# datapackage-query\nOpen datapackage.json and resource.csv files and query the contents\n",
"readmeFilename": "README.md",
"_id": "datapackage-query@0.1.0",
"dist": {
"shasum": "3852d56807c1a477d31f8d7190f5d54a12f3fc31"
},
"_from": "datapackage-query@^0.1.0",
"_resolved": "https://registry.npmjs.org/datapackage-query/-/datapackage-query-0.1.0.tgz"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc