2e54d47d81d84acbdc4d3fd71534f342c731343b01a433e04e7eb814b1d008cc3d8eee1476e59f884eefa966b89962bcd6ade3f5977a9237dc82b2da1cee92 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. interface StripLiteralOptions {
  2. /**
  3. * Will be called for each string literal. Return false to skip stripping.
  4. */
  5. filter?: (s: string) => boolean;
  6. /**
  7. * Fill the stripped literal with this character.
  8. * It must be a single character.
  9. *
  10. * @default ' '
  11. */
  12. fillChar?: string;
  13. }
  14. /**
  15. * Strip literal using Acorn's tokenizer.
  16. *
  17. * Will throw error if the input is not valid JavaScript.
  18. */
  19. declare function stripLiteralAcorn(code: string, options?: StripLiteralOptions): string;
  20. /**
  21. * Returns a function that returns whether the position is
  22. * in a literal using Acorn's tokenizer.
  23. *
  24. * Will throw error if the input is not valid JavaScript.
  25. */
  26. declare function createIsLiteralPositionAcorn(code: string): (position: number) => boolean;
  27. /**
  28. * Strip literal using RegExp.
  29. *
  30. * This will be faster and can work on non-JavaScript input.
  31. * But will have some caveats on distinguish strings and comments.
  32. */
  33. declare function stripLiteralRegex(code: string, options?: StripLiteralOptions): string;
  34. /**
  35. * Strip literal from code.
  36. *
  37. * Using Acorn's tokenizer first, and fallback to Regex if Acorn fails.
  38. */
  39. declare function stripLiteral(code: string, options?: StripLiteralOptions): string;
  40. /**
  41. * Strip literal from code, return more detailed information.
  42. *
  43. * Using Acorn's tokenizer first, and fallback to Regex if Acorn fails.
  44. */
  45. declare function stripLiteralDetailed(code: string, options?: StripLiteralOptions): {
  46. mode: 'acorn' | 'regex';
  47. result: string;
  48. acorn: {
  49. tokens: any[];
  50. error?: any;
  51. };
  52. };
  53. export { StripLiteralOptions, createIsLiteralPositionAcorn, stripLiteral, stripLiteralAcorn, stripLiteralDetailed, stripLiteralRegex };