@asset-pipe/common
Advanced tools
Comparing version 3.0.1 to 4.0.0-alpha.1
132
package.json
{ | ||
"name": "@asset-pipe/common", | ||
"version": "3.0.1", | ||
"author": { | ||
"name": "Trygve Lie", | ||
"email": "post@trygve-lie.com" | ||
}, | ||
"description": "Misc common methods", | ||
"main": "./lib/common.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/asset-pipe/asset-pipe-common.git" | ||
}, | ||
"keywords": [ | ||
"test" | ||
], | ||
"contributors": [ | ||
{ | ||
"name": "Trygve Lie", | ||
"email": "post@trygve-lie.com" | ||
"name": "@asset-pipe/common", | ||
"version": "4.0.0-alpha.1", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tap" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/asset-pipe/common.git" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/asset-pipe/common/issues" | ||
}, | ||
"homepage": "https://github.com/asset-pipe/common#readme", | ||
"dependencies": { | ||
"ajv": "^6.10.2" | ||
}, | ||
"devDependencies": { | ||
"tap": "^14.6.1" | ||
} | ||
], | ||
"bugs": { | ||
"url": "https://github.com/asset-pipe/asset-pipe-common/issues" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"readable-stream": "2.3.6" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^6.1.3", | ||
"@commitlint/config-conventional": "^6.1.3", | ||
"JSONStream": "1.3.1", | ||
"commitizen": "^2.9.6", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"eslint": "^4.8.1", | ||
"eslint-config-finn": "^3.0.0", | ||
"eslint-config-finn-prettier": "^3.0.1", | ||
"eslint-plugin-import": "^2.9.0", | ||
"husky": "^0.14.3", | ||
"jest": "^22.4.2", | ||
"lint-staged": "^7.0.0", | ||
"prettier": "^1.11.1", | ||
"travis-deploy-once": "^4.3.4", | ||
"semantic-release": "^15.0.1" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "jest --coverage", | ||
"lint:format": "eslint --fix .", | ||
"lint:commit": "commitlint --from=HEAD~1", | ||
"precommit": "lint-staged", | ||
"cm": "git-cz", | ||
"travis-deploy-once": "travis-deploy-once", | ||
"semantic-release": "semantic-release" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"jest": { | ||
"testEnvironment": "node", | ||
"clearMocks": true, | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100, | ||
"statements": 100 | ||
} | ||
} | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 4, | ||
"overrides": [ | ||
{ | ||
"files": "*.json", | ||
"options": { | ||
"tabWidth": 2 | ||
} | ||
}, | ||
{ | ||
"files": ".eslintrc", | ||
"options": { | ||
"parser": "json", | ||
"tabWidth": 2 | ||
} | ||
} | ||
] | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix --config ./.eslintrc", | ||
"git add" | ||
], | ||
"{*.json,*.md,.eslintrc}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
} | ||
} |
179
README.md
@@ -1,177 +0,20 @@ | ||
# @asset-pipe/common | ||
# Asset Pipe Common | ||
[![Travis CI Build Status](https://img.shields.io/travis/asset-pipe/asset-pipe-common/master.svg)](http://travis-ci.org/asset-pipe/asset-pipe-common) | ||
[![NPM version](https://img.shields.io/npm/v/@asset-pipe/common.svg)](https://npmjs.org/package/@asset-pipe/common) | ||
[![Dependency Status](https://img.shields.io/david/asset-pipe/asset-pipe-common.svg)](https://david-dm.org/asset-pipe/asset-pipe-common) | ||
[![Dev Dependency Status](https://img.shields.io/david/dev/asset-pipe/asset-pipe-common.svg)](https://david-dm.org/asset-pipe/asset-pipe-common#info=devDependencies) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/asset-pipe/@asset-pipe/common.svg)](https://greenkeeper.io/) | ||
This package contains common utilities and schemas | ||
Common utility methods shared accross the [asset-pipe project][asset-pipe]. Intended for use by other | ||
modules in the [asset-pipe project][asset-pipe] | ||
## APIs | ||
## Installation | ||
### schemas | ||
```bash | ||
$ npm install @asset-pipe/common | ||
``` | ||
#### assets | ||
## API | ||
This module have the following API: | ||
### IdHasher() | ||
Writable stream to build a hash out of all the `id` properties in an [asset feed](#data-format). | ||
```js | ||
const common = require('@asset-pipe/common'); | ||
const JSONStream = require('JSONStream'); | ||
const fs = require('fs'); | ||
const { schemas } = require('@asset-pipe/common'); | ||
const file = fs.createReadStream('./asset-feed.json'); | ||
const parser = JSONStream.parse('*'); | ||
const hasher = new common.IdHasher(); | ||
file.pipe(parser).pipe(hasher); | ||
hasher.on('finish', () => { | ||
console.log(hasher.hash); | ||
const { error, value } = schemas.assets({ | ||
organisation: 'my-org', | ||
name: 'my-app', | ||
version: '1.0.0', | ||
server: 'http://asset-server', | ||
}); | ||
``` | ||
### SourceHasher() | ||
Writable stream to build a hash out of all the `source` properties in an [asset feed](#data-format). | ||
```js | ||
const common = require('@asset-pipe/common'); | ||
const JSONStream = require('JSONStream'); | ||
const fs = require('fs'); | ||
const file = fs.createReadStream('./asset-feed.json'); | ||
const parser = JSONStream.parse('*'); | ||
const hasher = new common.SourceHasher(); | ||
file.pipe(parser).pipe(hasher); | ||
hasher.on('finish', () => { | ||
console.log(hasher.hash); | ||
}); | ||
``` | ||
### FileHasher() | ||
Writable stream to build a hash out of the content of a non object mode stream. | ||
```js | ||
const common = require('@asset-pipe/common'); | ||
const fs = require('fs'); | ||
const file = fs.createReadStream('./assets.js'); | ||
const hasher = new common.FileHasher(); | ||
file.pipe(hasher); | ||
hasher.on('finish', () => { | ||
console.log(hasher.hash); | ||
}); | ||
``` | ||
### hasher(source) | ||
Creates a hash out of a String or Buffer | ||
Arguments: | ||
* source - `String` or `Buffer` - the contents to hash | ||
Returns a hash. | ||
```js | ||
const common = require('@asset-pipe/common'); | ||
const fs = require('fs'); | ||
fs.readFile('.assets.js', (err, data) => { | ||
const hash = common.hasher(data); | ||
console.log(hash); | ||
}); | ||
``` | ||
### createTemporaryFilename(fileType) | ||
Creates a random file name intended to be used for temp files. | ||
Arguments: | ||
* fileType - `String` - extension to be used on the file. Ex; `json`. | ||
Returns a String of the following format: `tmp-{random-value}.{fileType}`. | ||
```js | ||
const common = require('@asset-pipe/common'); | ||
const tmpFile = common.createTemporaryFilename('json'); | ||
console.log(tmpFile); | ||
``` | ||
### hashArray(arr) | ||
Given an array of hashes, deterministically produces a single hash. Array order is important for determinism. | ||
Arguments: | ||
* arr = `string[]` - strings to be hashed together to produce a single hash | ||
Returns a promise that will resolve into a hash string. | ||
```js | ||
const { hashArray } = require('@asset-pipe/common'); | ||
const hash = await hashArray(['abc1a2b3', 'bac1a2b3', 'ca21a2b3']); | ||
console.log(hash); | ||
``` | ||
## Data format | ||
Some of the metods in this module operate on what we call the asset feed. What we refere to as an | ||
asset feed is the internal data format used in [Browserify][browserify]. We use the exact same | ||
data format as Browserify in the [asset-pipe project][asset-pipe]. | ||
When Browserify resolves [CommonJS modules][commonjs] each dependency will be read and transformed | ||
into an object which looks something like this: | ||
```json | ||
{ | ||
"id": "c645cf572a8f5acf8716e4846b408d3b1ca45c58", | ||
"source": | ||
"\"use strict\";module.exports.world=function(){return\"world\"};", | ||
"deps": {}, | ||
"file": "./assets/js/bar.js" | ||
} | ||
``` | ||
## License | ||
The MIT License (MIT) | ||
Copyright (c) 2017 - Trygve Lie - post@trygve-lie.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
[commonjs]: https://nodejs.org/docs/latest/api/modules.html | ||
[asset-pipe]: https://github.com/asset-pipe | ||
[browserify]: https://github.com/substack/node-browserify |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
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
1
6
284
9237
2
21
1
+ Addedajv@^6.10.2
+ Addedajv@6.12.6(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addeduri-js@4.4.1(transitive)
- Removedreadable-stream@2.3.6
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.6(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)