-
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.
Merge pull request #1 from Hajime-san/fix-encoding
fix encoding
- Loading branch information
Showing
7 changed files
with
47 additions
and
32 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 |
---|---|---|
|
@@ -4,51 +4,52 @@ This tool transforms your local TypeScript code that gives you to rewrite file e | |
## transform examples | ||
```ts | ||
export { foo } from "./foo" | ||
transform to | ||
// transform to | ||
export { foo } from "./foo.(ts|tsx|d.ts)" | ||
``` | ||
|
||
```ts | ||
import { bar } from "./bar" | ||
transform to | ||
// transform to | ||
import { bar } from "./bar.(ts|tsx|d.ts)" | ||
``` | ||
|
||
## limitation | ||
- Can't resolve `paths` alias of TypeScript compiler options. | ||
- Can't resolve `import()` syntax, commonly called `dynamic import`. | ||
- Can't keep `newline` of original source code. | ||
- Can't keep `single quatation` or `duble quatation` and `semicolon` of original source code. | ||
|
||
## command | ||
### remote | ||
- dry run | ||
- `deno run --unstable --allow-env --allow-read https://deno.land/x/[email protected].5/bin.ts -b=./src -c=./tsconfig.json -d` | ||
- `deno run --unstable --allow-env --allow-read https://deno.land/x/[email protected].6/bin.ts -b=./src -c=./tsconfig.json -d` | ||
- transform | ||
- `deno run --unstable --allow-env --allow-read --allow-write https://deno.land/x/[email protected].5/bin.ts -b=./src -c=./tsconfig.json -r` | ||
- `deno run --unstable --allow-env --allow-read --allow-write https://deno.land/x/[email protected].6/bin.ts -b=./src -c=./tsconfig.json -r` | ||
### local | ||
- `deno task run-dry` | ||
- `deno task run` | ||
|
||
### arguments | ||
| key | description | type | default | | ||
|-----|-----|-----|-----| | ||
| -b | local of base directory | `string` | `./` | | ||
| -b | local of base directory | `string` | `.` | | ||
| -c | local of base `tsconfig.json` | `string` | `./tsconfig.json` | | ||
| -d | dry run | `boolean` | `false` | | ||
| -r | enable repl interface | `boolean` | `false` | | ||
|
||
## tips | ||
After you ran `bin.ts`, you should run `npx tsc --noEmit` due to check correctness of transformation by this tool. | ||
- `tsconfig.json` example | ||
```json | ||
{ | ||
"compilerOptions": { | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"noEmit": true | ||
```json | ||
{ | ||
"compilerOptions": { | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"noEmit": true | ||
} | ||
} | ||
} | ||
``` | ||
``` | ||
|
||
## License | ||
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const hasUnicodeStr = (str: string): boolean => { | ||
return /\\u.{4}/gi.test(str); | ||
}; | ||
|
||
export const unescapeUnicodeStr = (str: string): string => { | ||
return unescape(str.replace(/\\u/g, '%u')); | ||
}; |
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 @@ | ||
import { asserts } from './dev_deps.ts'; | ||
import { hasUnicodeStr, unescapeUnicodeStr } from './str.ts'; | ||
const { assertEquals } = asserts; | ||
|
||
Deno.test('hasUnicodeStr', () => { | ||
// \uD83D\uDE0E is 😎 | ||
assertEquals(hasUnicodeStr('\\uD83D\\uDE0E'), true); | ||
}); | ||
|
||
Deno.test('unescapeUnicodeStr', () => { | ||
assertEquals(unescapeUnicodeStr('\uD83D\uDE0E'), '😎'); | ||
}); |