New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-string-extractor

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-string-extractor

Extracts the string literal contents of TypeScript function calls

1.0.0
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Extracts the string literal contents of TypeScript function calls.

Can also check that the function calls are valid calls to polyglot.t.

Usage

bin/ts-string-extractor -n function_name [-p tsconfig.json] [--check-polyglot] [--check-only] [file ...]

Example

Given a TypeScript file file.ts:

polyglot.t('hello');
polyglot.t('world');
polyglot.t('not' + 'valid');
polyglot.t("has a {name} but it's {missing}", {enam: 'whoops'});

Then running:

bin/ts-string-extractor -n polyglot.t --check-polyglot file.ts

Will yield JSON output:

{
  "hello": {
    "file": "file.ts",
    "line": 1,
    "column": 12
  },
  "world": {
    "file": "file.ts",
    "line": 2,
    "column": 12
  },
  "has a {name} but it's {missing}": {
    "file": "file.ts",
    "line": 4,
    "column": 12
  }
}

and errors:

Error in file.ts:3:12: First argument of polyglot.t('not' + 'valid') must be a string literal
Error in file.ts:4:12: Mismatched Polyglot substitution, text has [name,missing] but object literal has [enam]

Notes

  • Works with any file that the TypeScript compiler is able to understand, including .js, .jsx, and .tsx.
  • If -p tsconfig.json isn't specified then the tsconfig.json file in the current directory will be used, otherwise the default configuration.
  • A --check-only flag is provided that runs only the checkers, it doesn't generate any json output.

FAQs

Package last updated on 18 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts