asset-parser
Advanced tools
Comparing version 0.0.0 to 1.0.0
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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
112747
24
1505
0
1
241
0
3
21
+ Addeddiagnostics@^1.1.0
+ Addedrip-out@^1.0.0
+ Addedsvgs@^3.2.0
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedcolornames@1.1.1(transitive)
+ Addedcolorspace@1.1.4(transitive)
+ Addeddiagnostics@1.1.1(transitive)
+ Addedenabled@1.0.2(transitive)
+ Addedenv-variable@0.0.6(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedkuler@1.0.1(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact@19.0.0(transitive)
+ Addedreact-is@16.13.1(transitive)
+ Addedrip-out@1.0.0(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedsvgs@3.3.1(transitive)
+ Addedtext-hex@1.0.0(transitive)