strip-literal
Advanced tools
Comparing version 1.3.0 to 2.0.0
@@ -0,1 +1,4 @@ | ||
import * as js_tokens from 'js-tokens'; | ||
import { Token } from 'js-tokens'; | ||
interface StripLiteralOptions { | ||
@@ -15,28 +18,9 @@ /** | ||
/** | ||
* Strip literal using Acorn's tokenizer. | ||
* | ||
* Will throw error if the input is not valid JavaScript. | ||
*/ | ||
declare function stripLiteralAcorn(code: string, options?: StripLiteralOptions): string; | ||
/** | ||
* Returns a function that returns whether the position is | ||
* in a literal using Acorn's tokenizer. | ||
* | ||
* Will throw error if the input is not valid JavaScript. | ||
*/ | ||
declare function createIsLiteralPositionAcorn(code: string): (position: number) => boolean; | ||
declare function stripLiteralJsTokens(code: string, options?: StripLiteralOptions): { | ||
result: string; | ||
tokens: Token[]; | ||
}; | ||
/** | ||
* Strip literal using RegExp. | ||
* | ||
* This will be faster and can work on non-JavaScript input. | ||
* But will have some caveats on distinguish strings and comments. | ||
*/ | ||
declare function stripLiteralRegex(code: string, options?: StripLiteralOptions): string; | ||
/** | ||
* Strip literal from code. | ||
* | ||
* Using Acorn's tokenizer first, and fallback to Regex if Acorn fails. | ||
*/ | ||
@@ -46,14 +30,8 @@ declare function stripLiteral(code: string, options?: StripLiteralOptions): string; | ||
* Strip literal from code, return more detailed information. | ||
* | ||
* Using Acorn's tokenizer first, and fallback to Regex if Acorn fails. | ||
*/ | ||
declare function stripLiteralDetailed(code: string, options?: StripLiteralOptions): { | ||
mode: 'acorn' | 'regex'; | ||
result: string; | ||
acorn: { | ||
tokens: any[]; | ||
error?: any; | ||
}; | ||
tokens: js_tokens.Token[]; | ||
}; | ||
export { StripLiteralOptions, createIsLiteralPositionAcorn, stripLiteral, stripLiteralAcorn, stripLiteralDetailed, stripLiteralRegex }; | ||
export { type StripLiteralOptions, stripLiteral, stripLiteralDetailed, stripLiteralJsTokens }; |
{ | ||
"name": "strip-literal", | ||
"version": "1.3.0", | ||
"packageManager": "pnpm@8.6.11", | ||
"version": "2.0.0", | ||
"packageManager": "pnpm@8.13.1", | ||
"description": "Strip comments and string literals from JavaScript code", | ||
@@ -44,20 +44,20 @@ "author": "Anthony Fu <anthonyfu117@hotmail.com>", | ||
"dependencies": { | ||
"acorn": "^8.10.0" | ||
"js-tokens": "^8.0.2" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^0.40.0", | ||
"@antfu/ni": "^0.21.5", | ||
"@types/node": "^20.4.5", | ||
"bumpp": "^9.1.1", | ||
"eslint": "^8.46.0", | ||
"esmo": "^0.17.0", | ||
"pnpm": "^8.6.11", | ||
"rimraf": "^5.0.1", | ||
"three": "^0.155.0", | ||
"typescript": "^5.1.6", | ||
"unbuild": "^1.2.1", | ||
"vite": "^4.4.8", | ||
"vitest": "^0.34.1", | ||
"vue": "^3.3.4" | ||
"@antfu/eslint-config": "^2.6.1", | ||
"@antfu/ni": "^0.21.12", | ||
"@types/node": "^20.10.5", | ||
"bumpp": "^9.2.1", | ||
"eslint": "^8.56.0", | ||
"esmo": "^4.0.0", | ||
"pnpm": "^8.13.1", | ||
"rimraf": "^5.0.5", | ||
"three": "^0.160.0", | ||
"typescript": "^5.3.3", | ||
"unbuild": "^2.0.0", | ||
"vite": "^5.0.10", | ||
"vitest": "^1.1.0", | ||
"vue": "^3.4.0" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # strip-literal | ||
Strip comments and string literals from JavaScript code. Powered by [acorn](https://github.com/acornjs/acorn)'s tokenizer. | ||
Strip comments and string literals from JavaScript code. Powered by [`js-tokens`](https://github.com/lydell/js-tokens). | ||
@@ -20,35 +20,2 @@ ## Usage | ||
## Functions | ||
### `stripLiteralAcorn` | ||
Strip literal using [Acorn](https://github.com/acornjs/acorn)'s tokenizer. | ||
Will throw error if the input is not valid JavaScript. | ||
[Source](./src/acorn.ts) | ||
### `stripLiteralRegex` | ||
Strip literal using RegExp. | ||
This will be faster and can work on non-JavaScript input. But will have some caveats on distinguish strings and comments. | ||
[Source](./src/regex.ts) | ||
### `stripLiteral` | ||
Strip literal from code. | ||
Try to use `stripLiteralAcorn` first, and fallback to `stripLiteralRegex` if Acorn fails. | ||
[Source](./src/index.ts) | ||
### `createIsLiteralPositionAcorn` | ||
Returns a function that returns whether the position is in a literal using [Acorn](https://github.com/acornjs/acorn)'s tokenizer. | ||
Will throw error if the input is not valid JavaScript. | ||
[Source](./src/acorn.ts) | ||
## Sponsors | ||
@@ -55,0 +22,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
11097
182
30
+ Addedjs-tokens@^8.0.2
+ Addedjs-tokens@8.0.3(transitive)
- Removedacorn@^8.10.0
- Removedacorn@8.14.0(transitive)