Skip to content

Commit 7415c20

Browse files
committed
Convert project to TypeScript
1 parent c5f80ac commit 7415c20

9 files changed

+217
-33
lines changed

.eslintrc.json

-8
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules/
2+
index.js
3+
index.d.ts

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules/
22
test/
33
.eslintrc.json
44
.git*
5+
*.ts
6+
!*.d.ts
7+
tsconfig.json

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.3.0 (2019-04-16)
4+
**Dev Experience Changes**
5+
- Project now compiled with TypeScript and provides typings
6+
37
## v0.2.0 (2019-04-14)
48
**Parsing Behavior Changes**
59
- Now parses multiple nested quotes and content when there are no spaces [7d9b897](https://github.com/mccormicka/string-argv/commit/7d9b89730ea112b829f2591e3e9cae4c0d0cc285)

index.js renamed to index.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
"use strict";
21

3-
module.exports = parseArgsStringToArgv;
4-
module.exports.parseArgsStringToArgv = parseArgsStringToArgv;
5-
6-
function parseArgsStringToArgv(value, env, file) {
2+
export { parseArgsStringToArgv as default, parseArgsStringToArgv };
3+
function parseArgsStringToArgv(
4+
value: string,
5+
env?: string,
6+
file?: string
7+
): string[] {
78
// ([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*) Matches nested quotes until the first space outside of quotes
89

910
// [^\s'"]+ or Match if not a space ' or "
1011

1112
// (['"])([^\5]*?)\5 or Match "quoted text" without quotes
1213
// `\3` and `\5` are a backreference to the quote style (' or ") captured
13-
var myRegexp = /([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*)|[^\s'"]+|(['"])([^\5]*?)\5/gi;
14-
var myString = value;
15-
var myArray = [
16-
];
14+
const myRegexp = /([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*)|[^\s'"]+|(['"])([^\5]*?)\5/gi;
15+
const myString = value;
16+
const myArray: string[] = [];
1717
if (env) {
1818
myArray.push(env);
1919
}
2020
if (file) {
2121
myArray.push(file);
2222
}
23-
var match;
23+
let match: RegExpExecArray | null;
2424
do {
2525
// Each call to exec returns the next regex match as an array
2626
match = myRegexp.exec(myString);
2727
if (match !== null) {
2828
// Index 1 in the array is the captured group if it exists
2929
// Index 0 is the matched text, which we use if no captured group exists
30-
myArray.push(firstString(match[1], match[6], match[0]));
30+
myArray.push(firstString(match[1], match[6], match[0])!);
3131
}
3232
} while (match !== null);
3333

@@ -36,9 +36,9 @@ function parseArgsStringToArgv(value, env, file) {
3636

3737
// Accepts any number of arguments, and returns the first one that is a string
3838
// (even an empty string)
39-
function firstString() {
40-
for (var i = 0; i < arguments.length; i++) {
41-
var arg = arguments[i];
39+
function firstString(...args: Array<any>): string | undefined {
40+
for (let i = 0; i < args.length; i++) {
41+
const arg = args[i];
4242
if (typeof arg === "string") {
4343
return arg;
4444
}

package-lock.json

+125
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "string-argv",
33
"description": "string-argv parses a string into an argument array to mimic process.argv. This is useful when testing Command Line Utilities that you want to pass arguments to.",
4-
"version": "0.2.1",
4+
"version": "0.3.0",
55
"contributors": [
66
{
77
"name": "Michael Ferris",
@@ -17,10 +17,12 @@
1717
"argv"
1818
],
1919
"scripts": {
20-
"lint": "eslint .",
21-
"test": "jasmine --config=test/config.json && npm run lint"
20+
"build": "tsc -p .",
21+
"prepublishOnly": "npm test",
22+
"test": "npm run build & jasmine --config=test/config.json"
2223
},
2324
"main": "index",
25+
"types": "index.d.ts",
2426
"engines": {
2527
"node": ">=0.6.19"
2628
},
@@ -35,8 +37,7 @@
3537
"readmeFilename": "README.md",
3638
"dependencies": {},
3739
"devDependencies": {
38-
"eslint": "^2.0.0",
39-
"eslint-config-cellule": "^3.0.0",
40-
"jasmine": "^2.4.1"
40+
"jasmine": "^2.4.1",
41+
"typescript": "^3.4.3"
4142
}
4243
}

test/.eslintrc

-5
This file was deleted.

tsconfig.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es3", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
// "allowJs": true, /* Allow javascript files to be compiled. */
8+
// "checkJs": true, /* Report errors in .js files. */
9+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
"declaration": true, /* Generates corresponding '.d.ts' file. */
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
// "sourceMap": true, /* Generates corresponding '.map' file. */
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
// "outDir": "./", /* Redirect output structure to the directory. */
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "incremental": true, /* Enable incremental compilation */
18+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19+
// "removeComments": true, /* Do not emit comments to output. */
20+
// "noEmit": true, /* Do not emit outputs. */
21+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
22+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24+
25+
/* Strict Type-Checking Options */
26+
"strict": true, /* Enable all strict type-checking options. */
27+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28+
// "strictNullChecks": true, /* Enable strict null checks. */
29+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
30+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34+
35+
/* Additional Checks */
36+
// "noUnusedLocals": true, /* Report errors on unused locals. */
37+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
38+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40+
41+
/* Module Resolution Options */
42+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
44+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
45+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46+
// "typeRoots": [], /* List of folders to include type definitions from. */
47+
// "types": [], /* Type declaration files to be included in compilation. */
48+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
49+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
50+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51+
52+
/* Source Map Options */
53+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
54+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
55+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
56+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
57+
58+
/* Experimental Options */
59+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
60+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
61+
}
62+
}

0 commit comments

Comments
 (0)