Skip to content

Commit

Permalink
Auto-merge for PR #235 via VersionBot
Browse files Browse the repository at this point in the history
refactor: Remove lodash
  • Loading branch information
resin-io-modules-versionbot[bot] authored Dec 14, 2017
2 parents f1bef96 + 38e26ae commit b2d75c5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v5.2.11 - 2017-12-14

* Refactor: Remove lodash #235 [Jonas Hermsmeier]

## v5.2.10 - 2017-12-12

* Fix(package): Fix prebuild script being run on build #236 [Jonas Hermsmeier]
Expand Down
92 changes: 42 additions & 50 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

'use strict';

const _ = require('lodash');
const yaml = require('js-yaml');

/**
Expand Down Expand Up @@ -58,65 +57,58 @@ const yaml = require('js-yaml');
* > }
* > ]
*/

module.exports = (input) => {
if (_.isEmpty(_.trim(input))) {
if (!input || !input.trim()) {
return [];
}

return _.compact(_.map(input.split(/\n\s*\n/), (device) => {
device = _.chain(device)
.split('\n')
.filter((line) => {
return /^(\s\s-\s)?[a-z]+:/i.test(line);
})
.map((line) => {
return line
.replace(/\\[^.\\]/g, (match, index, string) => {
const escapedCharacter = _.last(match);

if (string[index - 1] === '\\' || _.includes([
'b',
'f',
'n',
'r',
't',
'v'
], escapedCharacter)) {
return match;
}
const allowedEscapes = [ 'b', 'f', 'n', 'r', 't', 'v' ];

return escapedCharacter;
})
return input.split(/\n\s*\n/g)
.map((device) => {
device = device.split(/\r?\n/g)
.filter((line) => {
return /^(\s\s-\s)?[a-z]+:/i.test(line);
})
.map((line) => {
return line
.replace(/\\[^.\\]/g, (match, index, string) => {
const escapedCharacter = match[match.length - 1];

// Remove non printable ascii characters
// See http://stackoverflow.com/a/24229554
.replace(/[^\x20-\x7E]+/g, '')
// Remove non printable ascii characters
// See http://stackoverflow.com/a/24229554
if (string[index - 1] === '\\' || allowedEscapes.indexOf(escapedCharacter) !== -1) {
return match;
}

.replace(/"/g, (match, index, string) => {
if (_.some([
string.indexOf('"') === index,
string.lastIndexOf('"') === index
])) {
return match;
}
return escapedCharacter;
})
.replace(/[^\x20-\x7E]+/g, '')
.replace(/"/g, (match, index, string) => {
if (string.indexOf('"') === index || string.lastIndexOf('"') === index) {
return match;
}

return '\\"';
});
})
.join('\n')
.value();
return '\\"';
});
})
.join('\n');

const result = yaml.safeLoad(device);
const result = yaml.safeLoad(device);

if (_.isString(result)) {
return _.object([ result ], [ null ]);
}
if (typeof result === 'string') {
const data = {};
data[result] = null;
return data;
}

if (!result || !result.device) {
return;
}
if (!result || !result.device) {
return null;
}

return result;
}));
return result;
})
.filter((result) => {
return Boolean(result);
});
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drivelist",
"version": "5.2.10",
"version": "5.2.11",
"description": "List all connected drives in your computer, in all major operating systems",
"main": "lib/drivelist.js",
"homepage": "https://github.com/resin-io-modules/drivelist",
Expand Down Expand Up @@ -51,7 +51,6 @@
"bindings": "^1.3.0",
"debug": "^3.1.0",
"js-yaml": "^3.10.0",
"lodash": "^4.16.4",
"nan": "^2.7.0",
"prebuild-install": "^2.3.0"
}
Expand Down
5 changes: 2 additions & 3 deletions tests/execute.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'use strict';

const m = require('mochainon');
const _ = require('lodash');
const os = require('os');
const childProcess = require('child_process');
const execute = require('../lib/execute');
Expand All @@ -27,7 +26,7 @@ describe('Execute', function() {
describe('.extractAndRun()', function() {

it('should be able to execute a script', function(done) {
const script = _.attempt(() => {
const script = (() => {
if (os.platform() === 'win32') {
return {
content: '@echo off\necho foo bar baz',
Expand All @@ -39,7 +38,7 @@ describe('Execute', function() {
content: '#!/bin/bash\necho "foo bar baz"',
originalFilename: 'hello.sh'
};
});
})();

execute.extractAndRun(script, (error, output) => {
m.chai.expect(error).to.not.exist;
Expand Down

0 comments on commit b2d75c5

Please sign in to comment.