Skip to content

Commit

Permalink
chore: port to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Nov 28, 2022
1 parent b210ea8 commit 69fc62f
Show file tree
Hide file tree
Showing 10 changed files with 6,270 additions and 2,692 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"google"
],
"globals": {
Expand Down
70 changes: 0 additions & 70 deletions chunk.js

This file was deleted.

68 changes: 68 additions & 0 deletions chunk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export const args = (str: string): string[] => {
const args = [];
str = str.trim();
let currentArg = '';
for (let i = 0; i < str.length; i++) {
switch (str[i]) {
case '\'':
const endQuoteIndex = str.indexOf('\'', i+1);
if (endQuoteIndex < 0) {
throw 'single quote not closed';
}
currentArg = currentArg + str.substring(i+1, endQuoteIndex);
i = endQuoteIndex;
break;
case '"':
// Double quotes can contain escaped characters
for (i++; i < str.length && str[i] !== '"'; i++) {
if (str[i] === '\\' && (i+1) < str.length) {
i++;
switch (str[i]) {
case 'n':
currentArg += '\n';
break;
case 'r':
currentArg += '\r';
break;
case 't':
currentArg += '\t';
break;
default:
currentArg += str[i];
}
} else {
currentArg += str[i];
}
}
if (i >= str.length) {
throw 'double quote not closed';
}
break;
case ' ':
case '\t':
args.push(currentArg);
currentArg = '';
while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
i++;
}
// We will have advanced to the next non-whitespace
i--;
break;
case '\\':
i++;
if (i < str.length) {
currentArg = currentArg + str[i];
} else {
throw 'uncompleted escape character';
}
break;
default:
currentArg = currentArg + str[i];
break;
}
}
if (currentArg != '') {
args.push(currentArg);
}
return args;
}
Loading

0 comments on commit 69fc62f

Please sign in to comment.