forked from waja/action-debian-package
		
	rewrite in javascript
This commit is contained in:
		
							parent
							
								
									b27c1f0ddb
								
							
						
					
					
						commit
						9feac88483
					
				
					 43 changed files with 2589 additions and 73 deletions
				
			
		
							
								
								
									
										18
									
								
								node_modules/firstline/.eslintrc.json
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								node_modules/firstline/.eslintrc.json
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
{
 | 
			
		||||
  "env": {
 | 
			
		||||
    "es6": true,
 | 
			
		||||
    "node": true,
 | 
			
		||||
    "mocha": true
 | 
			
		||||
  },
 | 
			
		||||
  "extends": "eslint:recommended",
 | 
			
		||||
  "parserOptions": {"sourceType": "module"},
 | 
			
		||||
  "rules": {
 | 
			
		||||
    "indent": ["error", 2],
 | 
			
		||||
    "keyword-spacing": "error",
 | 
			
		||||
    "linebreak-style": "error",
 | 
			
		||||
    "quotes": ["error","single"],
 | 
			
		||||
    "semi": "error",
 | 
			
		||||
    "space-before-blocks": "error",
 | 
			
		||||
    "space-before-function-paren": "error"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								node_modules/firstline/.travis.yml
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								node_modules/firstline/.travis.yml
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
language: node_js
 | 
			
		||||
cache:
 | 
			
		||||
  directories:
 | 
			
		||||
    - ~/.npm
 | 
			
		||||
notifications:
 | 
			
		||||
  email: false
 | 
			
		||||
node_js:
 | 
			
		||||
  - node
 | 
			
		||||
  - '6.4.0'
 | 
			
		||||
after_success:
 | 
			
		||||
  - npm run coverage
 | 
			
		||||
  - npm run travis-deploy-once "npm run semantic-release"
 | 
			
		||||
branches:
 | 
			
		||||
  except:
 | 
			
		||||
    - /^v\d+\.\d+\.\d+$/
 | 
			
		||||
							
								
								
									
										22
									
								
								node_modules/firstline/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								node_modules/firstline/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
The MIT License (MIT)
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2018 Alessandro Zanardi
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										50
									
								
								node_modules/firstline/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								node_modules/firstline/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
# Firstline
 | 
			
		||||
 | 
			
		||||
[](https://travis-ci.com/pensierinmusica/firstline)
 | 
			
		||||
[](https://coveralls.io/r/pensierinmusica/firstline)
 | 
			
		||||
[](https://www.npmjs.com/package/firstline)
 | 
			
		||||
[](https://www.npmjs.com/package/firstline)
 | 
			
		||||
[](https://www.npmjs.com/package/firstline)
 | 
			
		||||
 | 
			
		||||
## Introduction
 | 
			
		||||
 | 
			
		||||
Firstline is a [npm](http://npmjs.org) async module for [NodeJS](http://nodejs.org/), that **reads and returns the first line of any file**. It uses native JS promises and streams (requires Node >= v6.4.0). It is well tested and built for high performance.
 | 
			
		||||
 | 
			
		||||
It is particularly suited when you need to programmatically access the first line of a large amount of files, while handling errors if they occur.
 | 
			
		||||
 | 
			
		||||
## Install
 | 
			
		||||
 | 
			
		||||
`npm install firstline`
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
`firstline(filePath, [opts])`
 | 
			
		||||
 | 
			
		||||
- filePath (String): the full path to the file you want to read.
 | 
			
		||||
- opts (Object, optional):
 | 
			
		||||
  - encoding (String), set the file encoding (must be [supported by Node.js](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings)).
 | 
			
		||||
  - lineEnding (String), the character used for line ending (defaults to `\n`).
 | 
			
		||||
 | 
			
		||||
Incrementally reads data from `filePath` until it reaches the end of the first line.
 | 
			
		||||
 | 
			
		||||
Returns a promise, eventually fulfilled with a string.
 | 
			
		||||
 | 
			
		||||
## Examples
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
// Imagine the file content is:
 | 
			
		||||
// abc
 | 
			
		||||
// def
 | 
			
		||||
// ghi
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
firstline('./my-file.txt');
 | 
			
		||||
// -> Returns a promise that will be fulfilled with 'abc'.
 | 
			
		||||
 | 
			
		||||
firstline('./my-file.txt', { lineEnding: '\r' });
 | 
			
		||||
// -> Same as above, but using '\r' as line ending.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
***
 | 
			
		||||
 | 
			
		||||
MIT License
 | 
			
		||||
							
								
								
									
										30
									
								
								node_modules/firstline/index.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								node_modules/firstline/index.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
'use strict';
 | 
			
		||||
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
 | 
			
		||||
module.exports = (path, usrOpts) => {
 | 
			
		||||
  const opts = {
 | 
			
		||||
    encoding: 'utf8',
 | 
			
		||||
    lineEnding: '\n'
 | 
			
		||||
  };
 | 
			
		||||
  Object.assign(opts, usrOpts);
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    const rs = fs.createReadStream(path, {encoding: opts.encoding});
 | 
			
		||||
    let acc = '';
 | 
			
		||||
    let pos = 0;
 | 
			
		||||
    let index;
 | 
			
		||||
    rs
 | 
			
		||||
      .on('data', chunk => {
 | 
			
		||||
        index = chunk.indexOf(opts.lineEnding);
 | 
			
		||||
        acc += chunk;
 | 
			
		||||
        if (index === -1) {
 | 
			
		||||
          pos += chunk.length;
 | 
			
		||||
        } else {
 | 
			
		||||
          pos += index;
 | 
			
		||||
          rs.close();
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
      .on('close', () => resolve(acc.slice(acc.charCodeAt(0) === 0xFEFF ? 1 : 0, pos)))
 | 
			
		||||
      .on('error', err => reject(err));
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										85
									
								
								node_modules/firstline/package.json
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								node_modules/firstline/package.json
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,85 @@
 | 
			
		|||
{
 | 
			
		||||
  "_from": "firstline",
 | 
			
		||||
  "_id": "firstline@2.0.2",
 | 
			
		||||
  "_inBundle": false,
 | 
			
		||||
  "_integrity": "sha512-8KcmfI0jgSECnzdhucm0i7vrwef3BWwgjimW2YkRC5eSFwjb5DibVoA0YvgkYwwxuJi9c+7M7X3b3lX8o9B6wg==",
 | 
			
		||||
  "_location": "/firstline",
 | 
			
		||||
  "_phantomChildren": {},
 | 
			
		||||
  "_requested": {
 | 
			
		||||
    "type": "tag",
 | 
			
		||||
    "registry": true,
 | 
			
		||||
    "raw": "firstline",
 | 
			
		||||
    "name": "firstline",
 | 
			
		||||
    "escapedName": "firstline",
 | 
			
		||||
    "rawSpec": "",
 | 
			
		||||
    "saveSpec": null,
 | 
			
		||||
    "fetchSpec": "latest"
 | 
			
		||||
  },
 | 
			
		||||
  "_requiredBy": [
 | 
			
		||||
    "#USER",
 | 
			
		||||
    "/"
 | 
			
		||||
  ],
 | 
			
		||||
  "_resolved": "https://registry.npmjs.org/firstline/-/firstline-2.0.2.tgz",
 | 
			
		||||
  "_shasum": "3fdfd894a80e181cd2fa478b07cadb8d446c53cd",
 | 
			
		||||
  "_spec": "firstline",
 | 
			
		||||
  "_where": "/home/dawidd6/github/dawidd6/action-debian-package",
 | 
			
		||||
  "author": {
 | 
			
		||||
    "name": "Alessandro Zanardi"
 | 
			
		||||
  },
 | 
			
		||||
  "bugs": {
 | 
			
		||||
    "url": "https://github.com/pensierinmusica/firstline/issues"
 | 
			
		||||
  },
 | 
			
		||||
  "bundleDependencies": false,
 | 
			
		||||
  "config": {
 | 
			
		||||
    "commitizen": {
 | 
			
		||||
      "path": "./node_modules/cz-conventional-changelog"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "deprecated": false,
 | 
			
		||||
  "description": "Async npm module for Node JS that reads the first line of a file",
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "chai": "^4.1.2",
 | 
			
		||||
    "chai-as-promised": "^7.1.1",
 | 
			
		||||
    "coveralls": "^3.0.0",
 | 
			
		||||
    "cz-conventional-changelog": "^2.1.0",
 | 
			
		||||
    "eslint": "^4.19.1",
 | 
			
		||||
    "husky": "^0.14.3",
 | 
			
		||||
    "js-promisify": "^1.1.0",
 | 
			
		||||
    "mocha": "^5.1.1",
 | 
			
		||||
    "nyc": "^11.7.1",
 | 
			
		||||
    "rimraf": "^2.6.2",
 | 
			
		||||
    "semantic-release": "^15.5.0",
 | 
			
		||||
    "travis-deploy-once": "^5.0.0"
 | 
			
		||||
  },
 | 
			
		||||
  "engines": {
 | 
			
		||||
    "node": ">=6.4.0"
 | 
			
		||||
  },
 | 
			
		||||
  "homepage": "https://github.com/pensierinmusica/firstline",
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "read",
 | 
			
		||||
    "check",
 | 
			
		||||
    "file",
 | 
			
		||||
    "content",
 | 
			
		||||
    "filesystem",
 | 
			
		||||
    "io",
 | 
			
		||||
    "stream",
 | 
			
		||||
    "async",
 | 
			
		||||
    "promise"
 | 
			
		||||
  ],
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "name": "firstline",
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git+https://github.com/pensierinmusica/firstline.git"
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "coverage": "nyc report --reporter=text-lcov | coveralls",
 | 
			
		||||
    "lint": "eslint .",
 | 
			
		||||
    "pre-commit": "npm test",
 | 
			
		||||
    "semantic-release": "semantic-release",
 | 
			
		||||
    "test": "npm run lint && nyc mocha",
 | 
			
		||||
    "travis-deploy-once": "travis-deploy-once --pro"
 | 
			
		||||
  },
 | 
			
		||||
  "version": "2.0.2"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2
									
								
								node_modules/firstline/test/mocha.opts
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								node_modules/firstline/test/mocha.opts
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
--reporter spec
 | 
			
		||||
--ui bdd
 | 
			
		||||
							
								
								
									
										5
									
								
								node_modules/firstline/test/mocks.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								node_modules/firstline/test/mocks.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										79
									
								
								node_modules/firstline/test/test.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								node_modules/firstline/test/test.js
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,79 @@
 | 
			
		|||
'use strict';
 | 
			
		||||
 | 
			
		||||
const promisify = require('js-promisify');
 | 
			
		||||
const chai = require('chai');
 | 
			
		||||
const chaiAsPromised = require('chai-as-promised');
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const path = require('path');
 | 
			
		||||
const rimraf = require('rimraf');
 | 
			
		||||
 | 
			
		||||
const firstline = require('../index.js');
 | 
			
		||||
const mocks = require('./mocks.js');
 | 
			
		||||
 | 
			
		||||
chai.should();
 | 
			
		||||
chai.use(chaiAsPromised);
 | 
			
		||||
 | 
			
		||||
describe('firstline', () => {
 | 
			
		||||
 | 
			
		||||
  const dirPath = path.join(__dirname, 'tmp/');
 | 
			
		||||
  const filePath = dirPath + 'test.txt';
 | 
			
		||||
  const wrongFilePath = dirPath + 'no-test.txt';
 | 
			
		||||
 | 
			
		||||
  before(() => fs.mkdirSync(dirPath)); // Make "tmp" folder
 | 
			
		||||
 | 
			
		||||
  after(() => rimraf.sync(dirPath)); // Delete "tmp" folder
 | 
			
		||||
 | 
			
		||||
  describe('#check', () => {
 | 
			
		||||
 | 
			
		||||
    afterEach(() => rimraf.sync(filePath)); // Delete mock CSV file
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should reject if the file does not exist',
 | 
			
		||||
      () => firstline(wrongFilePath).should.be.rejected
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should return the first line of a file and default to `\\n` line ending',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, 'abc\ndef\nghi'])
 | 
			
		||||
        .then(() => firstline(filePath).should.eventually.equal('abc'))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should work correctly if the first line is long',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, mocks.longLine])
 | 
			
		||||
        .then(() => firstline(filePath).should.eventually.equal(mocks.longLine.split('\n')[0]))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should return an empty line if the file is empty',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, ''])
 | 
			
		||||
        .then(() => firstline(filePath).should.eventually.equal(''))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should work with a different encoding when specified correctly',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, 'abc\ndef\nghi', { encoding: 'ascii' }])
 | 
			
		||||
        .then(() => firstline(filePath, { encoding: 'ascii' }).should.eventually.equal('abc'))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should work with a different line ending when specified correctly',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, 'abc\rdef\rghi'])
 | 
			
		||||
        .then(() => firstline(filePath, { lineEnding: '\r' }).should.eventually.equal('abc'))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should return the entire file if the specified line ending is wrong',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, 'abc\ndef\nghi'])
 | 
			
		||||
        .then(() => firstline(filePath, { lineEnding: '\r' }).should.eventually.equal('abc\ndef\nghi'))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    it(
 | 
			
		||||
      'should handle BOM',
 | 
			
		||||
      () => promisify(fs.writeFile, [filePath, '\uFEFFabc\ndef'])
 | 
			
		||||
        .then(() => firstline(filePath).should.eventually.equal('abc'))
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue