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

asset-parser

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

asset-parser - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

.nyc_output/98106350522e134d5b3ec68e45fda149.json

125

index.js

@@ -1,1 +0,124 @@

console.log('asset-* project');
import { Pass, Through } from './passthrough';
import { encode, decode } from './packer';
import diagnostics from 'diagnostics';
import Asset from './asset';
//
// Setup our debug util.
//
const debug = diagnostics('asset:parser:transform');
/**
* The version of the specification that we currently follow.
*
* @type {String}
* @public
*/
export const version = '0.1.0';
/**
* Defines the parser function.
*
* @constructor
* @public
*/
export default class Parser {
constructor() {
this.version = version; // Version number of the spec we follow.
this.hooks = {}; // Stores our modifer functions.
}
/**
* Register a new modification hook.
*
* @param {String} name Name property the transformer should trigger on.
* @param {Function} fn Callback that transforms.
* @public
*/
modify(name, fn) {
debug(`registered a new tranform hook(${name})`);
if (!(name in this.hooks)) this.hooks[name] = [];
if (!~this.hooks[name].indexOf(fn)) this.hooks[name].push(fn);
}
/**
* Returns an array of properties that we have modifiers registered for.
*
* @returns {Array} List of properties.
* @public
*/
modifiers() {
return Object.keys(this.hooks);
}
/**
* Parse the received data.
*
* @param {String} format How is the data supplied.
* @param {String} str Input that needs to be parsed to individual assets.
* @param {Function} fn Error first completion callback.
* @public
*/
parse(format, str, fn) {
/**
* Transforms the data structure into a format that can be used by the
* React SVG Asset Provider.
*
* @param {Object} data Object where key is name, and value is an array.
* @param {String} spec Specification version in which the data is encoded.
* @private
*/
const transform = (data, spec) => {
const assets = Object.keys(data).reduce((memo, key) => {
if (Array.isArray(data[key])) {
debug(`transforming ${key} in to an Asset`);
memo[key] = new Asset(data[key], this.hooks, spec);
}
return memo;
}, {});
fn(null, assets);
};
/**
* Handle the decoded data and process it into Assets.
*
* @param {Error} err Optional error that happend during decoding.
* @param {Object} payload Data structure containing the svg names, data.
* @returns {Undefined} Nope.
* @private
*/
const decoded = (err, payload) => {
if (err) {
debug('failed to decode the supplied string, most likely invalid JSON', err);
return fn(err, {});
}
const data = payload.data;
const spec = payload.version;
if (typeof data === 'object' && !Array.isArray(data)) {
debug(`received correct payload, encoded in spec(${spec})`);
return transform(data, spec);
}
debug('incorrect payload structure', data, spec);
fn(new Error(`Failed to decode payload, spec(${spec})`), {});
};
decode(str, decoded);
}
}
//
// Export all the components, parsers and utilities.
//
export {
Pass,
Through,
encode,
decode,
Asset
};
{
"name": "asset-parser",
"version": "0.0.0",
"description": "Parses the result of asset-bundle into seperate SVG assets which can be rendered using React and React-Native",
"main": "index.js",
"version": "1.0.0",
"description": "Parse SVG asset bundles",
"main": "./lib/",
"browser": "./index",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test:web": "mocha --colors --require babel-register --require test/setup.js test/*.test.js",
"test": "nyc --reporter=text --reporter=json-summary npm run test:web",
"prepublish": "npm run build",
"build": "rm -rf ./lib && babel ./asset.js ./index.js ./packer/*.js ./passthrough/*.js ./transform.js -d ./lib",
"lint": "eslint-godaddy-react *.js packer/*.js passthrough/*.js ./test/*.js"
},
"author": "Arnout Kazemier",
"license": "MIT"
}
"homepage": "https://github.com/godaddy/asset-system/tree/master/packages/parser",
"repository": {
"type": "git",
"url": "git@github.com:godaddy/asset-system.git"
},
"keywords": [
"Asset",
"SVG",
"parser"
],
"babel": {
"plugins": [
"transform-object-rest-spread"
],
"presets": [
"babel-preset-es2015",
"babel-preset-react"
]
},
"browserify": {
"transform": [
"babelify"
]
},
"author": "GoDaddy.com Operating Company, LLC",
"contributors": [
"Arnout Kazemier <akazemier@godaddy.com>"
],
"license": "MIT",
"devDependencies": {
"assume": "^1.5.2",
"assume-enzyme": "^0.0.1",
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^4.14.0",
"eslint-config-godaddy-react": "^2.1.0",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-mocha": "^4.11.0",
"eslint-plugin-react": "^7.5.1",
"jsdom": "^11.5.1",
"mocha": "^5.0.1",
"nyc": "^11.4.1",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-test-renderer": "^16.2.0"
},
"dependencies": {
"diagnostics": "^1.1.0",
"rip-out": "^1.0.0",
"svgs": "^3.2.0"
}
}
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