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

chi-datapackage

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chi-datapackage - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0

dist/lib/resolve.js

3

CHANGELOG.md

@@ -9,2 +9,5 @@ CHANGELOG

## 5.0.0 (2016-09-30)
* Added observable Data Package store using mobx
## 4.0.2 (2016-09-22)

@@ -11,0 +14,0 @@ _(none)_

@@ -5,2 +5,3 @@ 'use strict';

var readFile = require('fs').readFile;
var fetchUrl = require('isomorphic-fetch');

@@ -7,0 +8,0 @@ var debug = require('debug')('fetch');

70

dist/loader.js

@@ -7,38 +7,9 @@ 'use strict';

var path = require('path');
var assert = require('assert');
var debug = require('debug')('Loader');
var identifier = require('datapackage-identifier');
var JSON5 = require('json5');
// const url = require('url');
var resolve = require('./lib/resolve');
var normalizeObject = require('./lib/utils').normalizeObject;
var absURLRegEx = /^([^\/]+:\/\/|\/)/;
// const forwardSlashPattern = /\//g;
var backSlashPattern = /\\/g;
// const protocolPattern = /^([a-z0-9.+-]+):\/\//i;
var resolvePath = function () {
/* istanbul ignore next , in browser*/
if (typeof document !== 'undefined') {
return function resolve(url) {
var div = document.createElement('div');
div.innerHTML = '<a></a>';
div.firstChild.href = url; // Ensures that the href is properly escaped
div.innerHTML = div.innerHTML; // Run the current innerHTML back through the parser
return div.firstChild.href;
};
}
return function (url) {
url = path.resolve(url) // ensures path is absolute
.replace(backSlashPattern, '/'); // ensures path is POSIX, ready to be a url
return url[0] === '/' ? url : '/' + url;
};
}();
function isFilePath(url) {
return !process.browser && url.indexOf('file://') === 0;
}
var Loader = function () {

@@ -56,3 +27,4 @@ function Loader(opts) {

value: function load(pathOrUrl) {
if (isFilePath(pathOrUrl)) {
if (!process.browser && pathOrUrl.indexOf('file://') === 0) {
assert(typeof this.read === 'function', 'loader.read is not allowed');
return this.read(pathOrUrl.replace('file://', ''));

@@ -66,8 +38,7 @@ }

debug('Loading datapackage', _datapackage);
if (typeof _datapackage === 'string') {
_datapackage = { path: _datapackage };
}
var id = getIdentifier(_datapackage);
_datapackage = normalizeObject(_datapackage);
var id = resolve.datapackage(_datapackage);
var url = id.dataPackageJsonUrl;
id.base = id.url;
Object.assign(_datapackage, id, { base: id.url });

@@ -78,3 +49,5 @@ if (!url) {

return this.load(url).catch(function (err) {
return this.load(url).then(JSON5.parse).then(function (res) {
return Object.assign(_datapackage, res);
}).catch(function (err) {
if (err.code === 'ENOENT') {

@@ -85,4 +58,2 @@ throw new Error('No DataPackage at path \'' + url + '\'');

throw err;
}).then(JSON5.parse).then(function (res) {
return Object.assign(res, _datapackage, id);
});

@@ -102,4 +73,4 @@ }

value: function resource(_resource) {
_resource = Object.assign({}, _resource);
debug('Loading resource', _resource);
_resource = normalizeObject(_resource);

@@ -127,19 +98,2 @@ var url = _resource.url;

Loader.id = getIdentifier;
function getIdentifier(datapackage) {
var url = datapackage.path || datapackage.url;
url = url.replace(backSlashPattern, '/');
if (!url.match(absURLRegEx)) {
url = resolvePath(url);
}
if (url.indexOf('file://') === 0) {
return {
url: url,
dataPackageJsonUrl: url
};
}
return identifier.parse(url);
}
module.exports = Loader;
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -11,5 +11,8 @@ 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 urijs = require('urijs');
var merge = require('lodash.merge');
var cuid = require('cuid');
var debug = require('debug')('Normalizer');
var resolve = require('./lib/resolve');
var normalizeObject = require('./lib/utils').normalizeObject;
var Normalizer = function () {

@@ -26,3 +29,6 @@ function Normalizer(opts) {

value: function datapackage(_datapackage) {
var path = _datapackage.path || _datapackage.url;
debug('Normalizing datapackage', _datapackage);
_datapackage = normalizeObject(_datapackage);
var path = _datapackage.path || _datapackage.url; // TODO: move into resolve.datapackage
var uri = urijs(path);

@@ -32,12 +38,16 @@ var dir = uri.normalizePathname().directory();

var normalized = merge({
var normalized = Object.assign({
path: path,
base: base,
name: dir,
resources: [],
homepage: base,
description: '',
schemas: {}
}, _datapackage);
}, _datapackage, {
resources: _datapackage.resources ? _datapackage.resources.slice() : []
});
var id = resolve.datapackage(normalized);
Object.assign(normalized, id, { base: id.url });
['image', 'readme'].forEach(function (key) {

@@ -54,9 +64,6 @@ if (Object.prototype.hasOwnProperty.call(normalized, key)) {

value: function resource(datapackage, _resource) {
if (typeof _resource === 'string') {
_resource = { path: _resource };
}
_resource = normalizeObject(_resource);
_resource = merge({}, _resource);
if (_resource.path || _resource.url) {
// TODO: move into resolve.resource
var uri = urijs(_resource.path || _resource.url);

@@ -82,2 +89,13 @@

}
}], [{
key: 'index',
value: function index(datapackage) {
var $resourcesByName = {};
datapackage.resources.forEach(function (r) {
if (r.name) {
$resourcesByName[r.name] = r;
}
});
return $resourcesByName;
}
}]);

@@ -88,14 +106,2 @@

function getResourceIndex(datapackage) {
var $resourcesByName = {};
datapackage.resources.forEach(function (r) {
if (r.name) {
$resourcesByName[r.name] = r;
}
});
return $resourcesByName;
}
Normalizer.index = getResourceIndex;
module.exports = Normalizer;
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -5,0 +5,0 @@ 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; }; }();

'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -122,3 +122,3 @@ 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; }; }();

resource.data.forEach(function (d, i) {
var r = merge({}, d);
var r = Object.assign({}, d);
var errors = [];

@@ -125,0 +125,0 @@ fields.forEach(function (field) {

@@ -0,7 +1,12 @@

const store = require('./src/store');
const Normalizer = require('./src/normalizer');
const DataPackageService = require('./src/service');
const dataPackageService = new DataPackageService();
const dataPackageService = store.dataPackageService;
dataPackageService.Normalizer = Normalizer;
dataPackageService.Resource = store.Resource;
dataPackageService.Package = store.Package;
dataPackageService.makeResource = store.makeResource;
dataPackageService.makePackage = store.makePackage;
module.exports = dataPackageService;
module.exports.Normalizer = Normalizer;
{
"name": "chi-datapackage",
"version": "4.0.2",
"version": "5.0.0",
"description": "Normalize datapackage and datapackage resources",

@@ -39,2 +39,3 @@ "main": "index.js",

"rules": {
"no-console": "warn",
"node/no-unsupported-features": [

@@ -86,2 +87,4 @@ 2,

"mime-lookup": "0.0.2",
"mobx": "^2.5.2",
"mobx-utils": "^1.1.0",
"parse-iso-duration": "^1.0.0",

@@ -88,0 +91,0 @@ "urijs": "^1.18.1"

const nodePath = require('path');
const readFile = require('fs').readFile;
const fetchUrl = require('isomorphic-fetch');

@@ -4,0 +5,0 @@ const debug = require('debug')('fetch');

'use strict';
const path = require('path');
const assert = require('assert');
const debug = require('debug')('Loader');
const identifier = require('datapackage-identifier');
const JSON5 = require('json5');
// const url = require('url');
const resolve = require('./lib/resolve');
const normalizeObject = require('./lib/utils').normalizeObject;
const absURLRegEx = /^([^\/]+:\/\/|\/)/;
// const forwardSlashPattern = /\//g;
const backSlashPattern = /\\/g;
// const protocolPattern = /^([a-z0-9.+-]+):\/\//i;
const resolvePath = (() => {
/* istanbul ignore next , in browser*/
if (typeof document !== 'undefined') {
return function resolve (url) {
const div = document.createElement('div');
div.innerHTML = '<a></a>';
div.firstChild.href = url; // Ensures that the href is properly escaped
div.innerHTML = div.innerHTML; // Run the current innerHTML back through the parser
return div.firstChild.href;
};
}
return url => {
url = path
.resolve(url) // ensures path is absolute
.replace(backSlashPattern, '/'); // ensures path is POSIX, ready to be a url
return (url[0] === '/') ? url : `/${url}`;
};
})();
function isFilePath (url) {
return (!process.browser && url.indexOf('file://') === 0);
}
class Loader {

@@ -48,3 +18,4 @@ constructor (opts) {

load (pathOrUrl) {
if (isFilePath(pathOrUrl)) {
if (!process.browser && pathOrUrl.indexOf('file://') === 0) {
assert(typeof this.read === 'function', 'loader.read is not allowed');
return this.read(pathOrUrl.replace('file://', ''));

@@ -57,8 +28,7 @@ }

debug('Loading datapackage', datapackage);
if (typeof datapackage === 'string') {
datapackage = {path: datapackage};
}
const id = getIdentifier(datapackage);
datapackage = normalizeObject(datapackage);
const id = resolve.datapackage(datapackage);
const url = id.dataPackageJsonUrl;
id.base = id.url;
Object.assign(datapackage, id, {base: id.url});

@@ -70,2 +40,4 @@ if (!url) {

return this.load(url)
.then(JSON5.parse)
.then(res => Object.assign(datapackage, res))
.catch(err => {

@@ -77,5 +49,3 @@ if (err.code === 'ENOENT') {

throw err;
})
.then(JSON5.parse)
.then(res => Object.assign(res, datapackage, id));
});
}

@@ -89,4 +59,4 @@

resource (resource) {
resource = Object.assign({}, resource);
debug('Loading resource', resource);
resource = normalizeObject(resource);

@@ -113,19 +83,2 @@ const url = resource.url;

Loader.id = getIdentifier;
function getIdentifier (datapackage) {
let url = datapackage.path || datapackage.url;
url = url.replace(backSlashPattern, '/');
if (!url.match(absURLRegEx)) {
url = resolvePath(url);
}
if (url.indexOf('file://') === 0) {
return {
url,
dataPackageJsonUrl: url
};
}
return identifier.parse(url);
}
module.exports = Loader;

@@ -5,5 +5,8 @@ 'use strict';

const urijs = require('urijs');
const merge = require('lodash.merge');
const cuid = require('cuid');
const debug = require('debug')('Normalizer');
const resolve = require('./lib/resolve');
const normalizeObject = require('./lib/utils').normalizeObject;
class Normalizer {

@@ -16,3 +19,6 @@ constructor (opts) {

datapackage (datapackage) {
const path = datapackage.path || datapackage.url;
debug('Normalizing datapackage', datapackage);
datapackage = normalizeObject(datapackage);
const path = datapackage.path || datapackage.url; // TODO: move into resolve.datapackage
const uri = urijs(path);

@@ -22,12 +28,16 @@ const dir = uri.normalizePathname().directory();

const normalized = merge({
const normalized = Object.assign({
path,
base,
name: dir,
resources: [],
homepage: base,
description: '',
schemas: {}
}, datapackage);
}, datapackage, {
resources: datapackage.resources ? datapackage.resources.slice() : []
});
const id = resolve.datapackage(normalized);
Object.assign(normalized, id, {base: id.url});
['image', 'readme'].forEach(key => {

@@ -43,9 +53,5 @@ if (Object.prototype.hasOwnProperty.call(normalized, key)) {

resource (datapackage, resource) {
if (typeof resource === 'string') {
resource = {path: resource};
}
resource = normalizeObject(resource);
resource = merge({}, resource);
if (resource.path || resource.url) {
if (resource.path || resource.url) { // TODO: move into resolve.resource
const uri = urijs(resource.path || resource.url);

@@ -71,16 +77,14 @@

}
}
function getResourceIndex (datapackage) {
const $resourcesByName = {};
datapackage.resources.forEach(r => {
if (r.name) {
$resourcesByName[r.name] = r;
}
});
return $resourcesByName;
static index (datapackage) {
const $resourcesByName = {};
datapackage.resources.forEach(r => {
if (r.name) {
$resourcesByName[r.name] = r;
}
});
return $resourcesByName;
}
}
Normalizer.index = getResourceIndex;
module.exports = Normalizer;

@@ -105,3 +105,3 @@ 'use strict';

resource.data.forEach((d, i) => {
const r = merge({}, d);
const r = Object.assign({}, d);
const errors = [];

@@ -108,0 +108,0 @@ fields.forEach(field => {

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