forked from yargs/yargs-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ts): init typescript conf + tsify tokenize-arg-string (yargs…
- Loading branch information
Showing
12 changed files
with
242 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.ts", | ||
"parser": "@typescript-eslint/parser", | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"no-useless-constructor": "off", | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"@typescript-eslint/no-useless-constructor": "error" | ||
} | ||
} | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint/eslint-plugin" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea | ||
build/ | ||
.nyc_output | ||
node_modules | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"spec": [ | ||
"build/test", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"exclude": [ | ||
"build/test/**", | ||
"test/**" | ||
], | ||
"reporter": [ | ||
"html", | ||
"text" | ||
], | ||
"lines": 100, | ||
"branches": "97", | ||
"statements": "100" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* global describe, it */ | ||
import { expect, should } from 'chai' | ||
import { tokenizeArgString } from '../lib/tokenize-arg-string' | ||
|
||
should() | ||
|
||
describe('TokenizeArgString', function () { | ||
it('handles unquoted string', function () { | ||
const args = tokenizeArgString('--foo 99') | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('99') | ||
}) | ||
|
||
it('handles unquoted numbers', function () { | ||
const args = tokenizeArgString(['--foo', 9]) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('9') | ||
}) | ||
|
||
it('handles quoted string with no spaces', function () { | ||
const args = tokenizeArgString("--foo 'hello'") | ||
args[0].should.equal('--foo') | ||
args[1].should.equal("'hello'") | ||
}) | ||
|
||
it('handles single quoted string with spaces', function () { | ||
const args = tokenizeArgString("--foo 'hello world' --bar='foo bar'") | ||
args[0].should.equal('--foo') | ||
args[1].should.equal("'hello world'") | ||
args[2].should.equal("--bar='foo bar'") | ||
}) | ||
|
||
it('handles double quoted string with spaces', function () { | ||
const args = tokenizeArgString('--foo "hello world" --bar="foo bar"') | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('"hello world"') | ||
args[2].should.equal('--bar="foo bar"') | ||
}) | ||
|
||
it('handles single quoted empty string', function () { | ||
const args = tokenizeArgString('--foo \'\' --bar=\'\'') | ||
args[0].should.equal('--foo') | ||
args[1].should.equal("''") | ||
args[2].should.equal("--bar=''") | ||
}) | ||
|
||
it('handles double quoted empty string', function () { | ||
const args = tokenizeArgString('--foo "" --bar=""') | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('""') | ||
args[2].should.equal('--bar=""') | ||
}) | ||
|
||
it('handles quoted string with embedded quotes', function () { | ||
var args = tokenizeArgString('--foo "hello \'world\'" --bar=\'foo "bar"\'') | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('"hello \'world\'"') | ||
args[2].should.equal('--bar=\'foo "bar"\'') | ||
}) | ||
|
||
// https://github.com/yargs/yargs-parser/pull/100 | ||
// https://github.com/yargs/yargs-parser/pull/106 | ||
it('ignores unneeded spaces', function () { | ||
const args = tokenizeArgString(' foo bar "foo bar" ') | ||
args[0].should.equal('foo') | ||
expect(args[1]).equal('bar') | ||
expect(args[2]).equal('"foo bar"') | ||
}) | ||
|
||
it('handles boolean options', function () { | ||
const args = tokenizeArgString('--foo -bar') | ||
expect(args[0]).to.equal(('--foo')) | ||
expect(args[1]).to.equal(('-bar')) | ||
}) | ||
|
||
it('handles empty string', function () { | ||
const args = tokenizeArgString('') | ||
expect(args.length).to.equal(0) | ||
}) | ||
|
||
it('handles array with unquoted string', function () { | ||
const args = tokenizeArgString(['--foo', '99']) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('99') | ||
}) | ||
|
||
it('handles array with quoted string with no spaces', function () { | ||
const args = tokenizeArgString(['--foo', "'hello'"]) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal("'hello'") | ||
}) | ||
|
||
it('handles array with single quoted string with spaces', function () { | ||
const args = tokenizeArgString(['--foo', "'hello world'", "--bar='foo bar'"]) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal("'hello world'") | ||
args[2].should.equal("--bar='foo bar'") | ||
}) | ||
|
||
it('handles array with double quoted string with spaces', function () { | ||
const args = tokenizeArgString(['--foo', '"hello world"', '--bar="foo bar"']) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('"hello world"') | ||
args[2].should.equal('--bar="foo bar"') | ||
}) | ||
|
||
it('handles array with single quoted empty string', function () { | ||
const args = tokenizeArgString(['--foo', "''", "--bar=''"]) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal("''") | ||
args[2].should.equal("--bar=''") | ||
}) | ||
|
||
it('handles array with double quoted empty string', function () { | ||
const args = tokenizeArgString(['--foo', '""', '--bar=""']) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('""') | ||
args[2].should.equal('--bar=""') | ||
}) | ||
|
||
it('handles array with quoted string with embedded quotes', function () { | ||
var args = tokenizeArgString(['--foo', '"hello \'world\'"', '--bar=\'foo "bar"\'']) | ||
args[0].should.equal('--foo') | ||
args[1].should.equal('"hello \'world\'"') | ||
args[2].should.equal('--bar=\'foo "bar"\'') | ||
}) | ||
|
||
it('handles array with boolean options', function () { | ||
const args = tokenizeArgString(['--foo', '-bar']) | ||
expect(args[0]).to.equal('--foo') | ||
expect(args[1]).to.equal('-bar') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./node_modules/gts/tsconfig-google.json", | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"rootDir": ".", | ||
"sourceMap": false | ||
}, | ||
"include": [ | ||
"lib/**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"sourceMap": true | ||
}, | ||
"include": [ | ||
"lib/**/*.ts", | ||
"test/**/*.ts" | ||
] | ||
} |