Add minified version

This commit is contained in:
Wessel T
2019-02-16 14:27:37 +01:00
parent fee7268445
commit c0049e5561
7 changed files with 64 additions and 30 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
yarn.lock
node_modules/

1
dist/larg.min.js vendored Normal file
View File

@@ -0,0 +1 @@
module.exports=(e=>{let t={},r=[];const s=e=>e.replace(/^\-+/g,""),l=e=>isNaN(e)?"true"===e.toString().toLowerCase()||"false"!==e.toString().toLowerCase()&&e:Number(e);for(let o=0;o<e.length;o++){const a=e[i].indexOf("="),c="-"===e[i].charAt(0)&&e.length-1>=i+1&&-1===e[o+1].indexOf("=")&&"-"!==e[o+1].charAt(0),n=s(-1===a?e[o]:e[o].slice(0,a));if(-1!==a)t[n]=l(e[i].slice(a+1));else if(c)t[n]=l(e[o+1]),o++;else if("-"===e[o].charAt(0))if("-"===e[o].charAt(1))t[n]=!0;else for(let e=0;e<n.length;e++)t[n.charAt(e)]=!0;else r.push(l(n))}return Object.assign(t,{_:r})});

6
gulpfile.js Normal file
View File

@@ -0,0 +1,6 @@
const gulp = require('gulp');
const minify = require('gulp-minify');
gulp.task('build:node', () => {
return gulp.src('larg.js').pipe(minify({ noSource: true, ext: { min: '.min.js' } })).pipe(gulp.dest('dist'));
});

View File

@@ -1,24 +0,0 @@
module.exports = ( args ) => {
let p = {};
let l = [];
const rHyphens = ( v ) => v.replace(/^\-+/g, '');
const cApplicable = ( v ) => ( isNaN( v ) ? ( v.toString().toLowerCase() === 'true' ? true : ( v.toString().toLowerCase() === 'false' ? false : v ) ) : Number( v ) );
for ( let i = 0; i < args.length; i++ ) {
const e = args[ i ].indexOf( '=' );
const r = args[ i ].charAt( 0 ) === '-' && args.length - 1 >= i + 1 && args[ i + 1 ].indexOf( '=' ) === -1 && args[ i + 1 ].charAt( 0 ) !== '-';
const n = e === -1 ? rHyphens( args[ i ] ) : rHyphens( args[ i ].slice( 0, e ) );
if ( e !== -1 ) p[ n ] = cApplicable( args[ i ].slice( e + 1 ) );
else if ( r ) {
p[ n ] = cApplicable( args[ i + 1 ] );
i++;
} else if ( args[ i ].charAt( 0 ) === '-' ) {
if ( args[ i ].charAt( 1 ) === '-' ) p[ n ] = true;
else for ( let b = 0; b < n.length; b++ ) p[ n.charAt( b ) ] = true;
} else l.push( cApplicable( n ) );
}
return Object.assign( p, { '_': l } );
};

View File

29
larg.js Normal file
View File

@@ -0,0 +1,29 @@
/**
* Parse arguments of an array
* @param {Array} args - The arguments to parse
* @returns {Object} - The parsed arguments
*/
module.exports = (args) => {
let p = {};
let l = [];
const rHyphens = (v) => v.replace(/^\-+/g, '');
const cApplicable = (v) => ( isNaN(v) ? (v.toString().toLowerCase() === 'true' ? true : (v.toString().toLowerCase() === 'false' ? false : v)) : Number(v));
for (let _ = 0; _ < args.length; _++) {
const e = args[i].indexOf('=');
const r = args[i].charAt(0) === '-' && args.length - 1 >= i + 1 && args[_ + 1].indexOf('=') === -1 && args[_ + 1].charAt(0) !== '-';
const n = e === -1 ? rHyphens(args[_]) : rHyphens(args[_].slice(0, e));
if ( e !== -1 ) p[ n ] = cApplicable( args[ i ].slice(e + 1));
else if (r) {
p[n] = cApplicable(args[_ + 1] );
_++;
} else if (args[_].charAt(0) === '-') {
if (args[_].charAt(1) === '-' ) p[n] = true;
else for (let b = 0; b < n.length; b++) p[n.charAt(b)] = true;
} else l.push(cApplicable(n));
}
return Object.assign(p, { '_': l });
};

View File

@@ -1,12 +1,17 @@
{
"name": "larg",
"version": "0.0.1",
"version": "0.0.2",
"description": "👾 A very lightweight Node.js argument parser",
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
"license": "MIT",
"main": "index.js",
"files": [ "index.js", "LICENSE" ],
"bugs": { "url": "https://www.github.com/PassTheWessel/larg/issues" },
"main": "larg.js",
"files": [
"larg.js",
"LICENSE"
],
"bugs": {
"url": "https://www.github.com/PassTheWessel/larg/issues"
},
"homepage": "https://www.github.com/PassTheWessel/larg#readme",
"types": "index.d.ts",
"repository": {
@@ -16,5 +21,20 @@
"scripts": {
"test": "node test.js"
},
"keywords": [ "argument", "args", "arg", "argv", "parse", "cli", "command-line", "parser", "command", "lightweight" ]
"keywords": [
"argument",
"args",
"arg",
"argv",
"parse",
"cli",
"command-line",
"parser",
"command",
"lightweight"
],
"devDependencies": {
"gulp": "^4.0.0",
"gulp-minify": "^3.1.0"
}
}