feat: init
This commit is contained in:
88
node_modules/strip-literal/dist/index.cjs
generated
vendored
Normal file
88
node_modules/strip-literal/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
|
||||
const jsTokens = require('js-tokens');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const jsTokens__default = /*#__PURE__*/_interopDefaultCompat(jsTokens);
|
||||
|
||||
const FILL_COMMENT = " ";
|
||||
function stripLiteralFromToken(token, fillChar, filter) {
|
||||
if (token.type === "SingleLineComment") {
|
||||
return FILL_COMMENT.repeat(token.value.length);
|
||||
}
|
||||
if (token.type === "MultiLineComment") {
|
||||
return token.value.replace(/[^\n]/g, FILL_COMMENT);
|
||||
}
|
||||
if (token.type === "StringLiteral") {
|
||||
if (!token.closed) {
|
||||
return token.value;
|
||||
}
|
||||
const body = token.value.slice(1, -1);
|
||||
if (filter(body)) {
|
||||
return token.value[0] + fillChar.repeat(body.length) + token.value[token.value.length - 1];
|
||||
}
|
||||
}
|
||||
if (token.type === "NoSubstitutionTemplate") {
|
||||
const body = token.value.slice(1, -1);
|
||||
if (filter(body)) {
|
||||
return `\`${body.replace(/[^\n]/g, fillChar)}\``;
|
||||
}
|
||||
}
|
||||
if (token.type === "RegularExpressionLiteral") {
|
||||
const body = token.value;
|
||||
if (filter(body)) {
|
||||
return body.replace(/\/(.*)\/(\w?)$/g, (_, $1, $2) => `/${fillChar.repeat($1.length)}/${$2}`);
|
||||
}
|
||||
}
|
||||
if (token.type === "TemplateHead") {
|
||||
const body = token.value.slice(1, -2);
|
||||
if (filter(body)) {
|
||||
return `\`${body.replace(/[^\n]/g, fillChar)}\${`;
|
||||
}
|
||||
}
|
||||
if (token.type === "TemplateTail") {
|
||||
const body = token.value.slice(0, -2);
|
||||
if (filter(body)) {
|
||||
return `}${body.replace(/[^\n]/g, fillChar)}\``;
|
||||
}
|
||||
}
|
||||
if (token.type === "TemplateMiddle") {
|
||||
const body = token.value.slice(1, -2);
|
||||
if (filter(body)) {
|
||||
return `}${body.replace(/[^\n]/g, fillChar)}\${`;
|
||||
}
|
||||
}
|
||||
return token.value;
|
||||
}
|
||||
function optionsWithDefaults(options) {
|
||||
return {
|
||||
fillChar: options?.fillChar ?? " ",
|
||||
filter: options?.filter ?? (() => true)
|
||||
};
|
||||
}
|
||||
function stripLiteral(code, options) {
|
||||
let result = "";
|
||||
const _options = optionsWithDefaults(options);
|
||||
for (const token of jsTokens__default(code, { jsx: false })) {
|
||||
result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function stripLiteralDetailed(code, options) {
|
||||
let result = "";
|
||||
const tokens = [];
|
||||
const _options = optionsWithDefaults(options);
|
||||
for (const token of jsTokens__default(code, { jsx: false })) {
|
||||
tokens.push(token);
|
||||
result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
|
||||
}
|
||||
return {
|
||||
result,
|
||||
tokens
|
||||
};
|
||||
}
|
||||
|
||||
exports.stripLiteral = stripLiteral;
|
||||
exports.stripLiteralDetailed = stripLiteralDetailed;
|
||||
exports.stripLiteralJsTokens = stripLiteralDetailed;
|
||||
30
node_modules/strip-literal/dist/index.d.cts
generated
vendored
Normal file
30
node_modules/strip-literal/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Token } from 'js-tokens';
|
||||
|
||||
interface StripLiteralOptions {
|
||||
/**
|
||||
* Will be called for each string literal. Return false to skip stripping.
|
||||
*/
|
||||
filter?: (s: string) => boolean;
|
||||
/**
|
||||
* Fill the stripped literal with this character.
|
||||
* It must be a single character.
|
||||
*
|
||||
* @default ' '
|
||||
*/
|
||||
fillChar?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip literal from code.
|
||||
*/
|
||||
declare function stripLiteral(code: string, options?: StripLiteralOptions): string;
|
||||
/**
|
||||
* Strip literal from code, return more detailed information.
|
||||
*/
|
||||
declare function stripLiteralDetailed(code: string, options?: StripLiteralOptions): {
|
||||
result: string;
|
||||
tokens: Token[];
|
||||
};
|
||||
|
||||
export { stripLiteral, stripLiteralDetailed, stripLiteralDetailed as stripLiteralJsTokens };
|
||||
export type { StripLiteralOptions };
|
||||
30
node_modules/strip-literal/dist/index.d.mts
generated
vendored
Normal file
30
node_modules/strip-literal/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Token } from 'js-tokens';
|
||||
|
||||
interface StripLiteralOptions {
|
||||
/**
|
||||
* Will be called for each string literal. Return false to skip stripping.
|
||||
*/
|
||||
filter?: (s: string) => boolean;
|
||||
/**
|
||||
* Fill the stripped literal with this character.
|
||||
* It must be a single character.
|
||||
*
|
||||
* @default ' '
|
||||
*/
|
||||
fillChar?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip literal from code.
|
||||
*/
|
||||
declare function stripLiteral(code: string, options?: StripLiteralOptions): string;
|
||||
/**
|
||||
* Strip literal from code, return more detailed information.
|
||||
*/
|
||||
declare function stripLiteralDetailed(code: string, options?: StripLiteralOptions): {
|
||||
result: string;
|
||||
tokens: Token[];
|
||||
};
|
||||
|
||||
export { stripLiteral, stripLiteralDetailed, stripLiteralDetailed as stripLiteralJsTokens };
|
||||
export type { StripLiteralOptions };
|
||||
30
node_modules/strip-literal/dist/index.d.ts
generated
vendored
Normal file
30
node_modules/strip-literal/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Token } from 'js-tokens';
|
||||
|
||||
interface StripLiteralOptions {
|
||||
/**
|
||||
* Will be called for each string literal. Return false to skip stripping.
|
||||
*/
|
||||
filter?: (s: string) => boolean;
|
||||
/**
|
||||
* Fill the stripped literal with this character.
|
||||
* It must be a single character.
|
||||
*
|
||||
* @default ' '
|
||||
*/
|
||||
fillChar?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip literal from code.
|
||||
*/
|
||||
declare function stripLiteral(code: string, options?: StripLiteralOptions): string;
|
||||
/**
|
||||
* Strip literal from code, return more detailed information.
|
||||
*/
|
||||
declare function stripLiteralDetailed(code: string, options?: StripLiteralOptions): {
|
||||
result: string;
|
||||
tokens: Token[];
|
||||
};
|
||||
|
||||
export { stripLiteral, stripLiteralDetailed, stripLiteralDetailed as stripLiteralJsTokens };
|
||||
export type { StripLiteralOptions };
|
||||
80
node_modules/strip-literal/dist/index.mjs
generated
vendored
Normal file
80
node_modules/strip-literal/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import jsTokens from 'js-tokens';
|
||||
|
||||
const FILL_COMMENT = " ";
|
||||
function stripLiteralFromToken(token, fillChar, filter) {
|
||||
if (token.type === "SingleLineComment") {
|
||||
return FILL_COMMENT.repeat(token.value.length);
|
||||
}
|
||||
if (token.type === "MultiLineComment") {
|
||||
return token.value.replace(/[^\n]/g, FILL_COMMENT);
|
||||
}
|
||||
if (token.type === "StringLiteral") {
|
||||
if (!token.closed) {
|
||||
return token.value;
|
||||
}
|
||||
const body = token.value.slice(1, -1);
|
||||
if (filter(body)) {
|
||||
return token.value[0] + fillChar.repeat(body.length) + token.value[token.value.length - 1];
|
||||
}
|
||||
}
|
||||
if (token.type === "NoSubstitutionTemplate") {
|
||||
const body = token.value.slice(1, -1);
|
||||
if (filter(body)) {
|
||||
return `\`${body.replace(/[^\n]/g, fillChar)}\``;
|
||||
}
|
||||
}
|
||||
if (token.type === "RegularExpressionLiteral") {
|
||||
const body = token.value;
|
||||
if (filter(body)) {
|
||||
return body.replace(/\/(.*)\/(\w?)$/g, (_, $1, $2) => `/${fillChar.repeat($1.length)}/${$2}`);
|
||||
}
|
||||
}
|
||||
if (token.type === "TemplateHead") {
|
||||
const body = token.value.slice(1, -2);
|
||||
if (filter(body)) {
|
||||
return `\`${body.replace(/[^\n]/g, fillChar)}\${`;
|
||||
}
|
||||
}
|
||||
if (token.type === "TemplateTail") {
|
||||
const body = token.value.slice(0, -2);
|
||||
if (filter(body)) {
|
||||
return `}${body.replace(/[^\n]/g, fillChar)}\``;
|
||||
}
|
||||
}
|
||||
if (token.type === "TemplateMiddle") {
|
||||
const body = token.value.slice(1, -2);
|
||||
if (filter(body)) {
|
||||
return `}${body.replace(/[^\n]/g, fillChar)}\${`;
|
||||
}
|
||||
}
|
||||
return token.value;
|
||||
}
|
||||
function optionsWithDefaults(options) {
|
||||
return {
|
||||
fillChar: options?.fillChar ?? " ",
|
||||
filter: options?.filter ?? (() => true)
|
||||
};
|
||||
}
|
||||
function stripLiteral(code, options) {
|
||||
let result = "";
|
||||
const _options = optionsWithDefaults(options);
|
||||
for (const token of jsTokens(code, { jsx: false })) {
|
||||
result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function stripLiteralDetailed(code, options) {
|
||||
let result = "";
|
||||
const tokens = [];
|
||||
const _options = optionsWithDefaults(options);
|
||||
for (const token of jsTokens(code, { jsx: false })) {
|
||||
tokens.push(token);
|
||||
result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
|
||||
}
|
||||
return {
|
||||
result,
|
||||
tokens
|
||||
};
|
||||
}
|
||||
|
||||
export { stripLiteral, stripLiteralDetailed, stripLiteralDetailed as stripLiteralJsTokens };
|
||||
Reference in New Issue
Block a user