npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ev1stensberg/strings-js

v1.0.0

Published

Read a JavaScript file and parse its strings into an array (AST-based, powered by the TypeScript compiler).

Readme

strings-js

A small TypeScript library and CLI that reads JavaScript (or TypeScript) and parses its strings into an array.

It uses the TypeScript compiler to build an abstract syntax tree, so it collects real strings from the code and ignores things like text inside comments. It captures three kinds of strings:

  • String literals'hello', "world"
  • Template literals`hi ${name}` (interpolation slots are shown as ${...})
  • Object property keys — the "foo" in { "foo": 1 }

You can feed it either a file path or raw source content — both from code (as a library) and from the command line.

Install

npm install
npm run build

The only runtime dependency is typescript.

Use as a library

import {
  parseStrings,
  parseStringsDetailed,
  parseStringsFromFile,
  parseStringsDetailedFromFile,
} from "strings-js";

// --- From raw source content ---
const code = `const greeting = "hello"; const t = \`hi \${name}\`; const o = { "key": 1 };`;

parseStrings(code);
// => ["hello", "hi ${...}", "key"]

parseStringsDetailed(code);
// => [
//   { value: "hello",     kind: "literal",     line: 1, column: 18 },
//   { value: "hi ${...}", kind: "template",    line: 1, column: 43 },
//   { value: "key",       kind: "propertyKey", line: 1, column: 68 },
// ]

// --- From a file on disk (language inferred from the extension) ---
parseStringsFromFile("./app.js");
parseStringsDetailedFromFile("./module.ts"); // .ts/.tsx/.jsx auto-detected

parseStrings / parseStringsDetailed take raw content; the ...FromFile variants read a path and are thin wrappers around them.

Options

Every function takes an optional second ParseStringsOptions argument:

| Option | Default | Description | | -------------- | ------- | -------------------------------------------------- | | literals | true | Include single/double-quoted string literals | | templates | true | Include template (backtick) literals | | propertyKeys | true | Include string-valued object property keys | | jsx | true | Enable JSX syntax when parsing | | typescript | false | Parse the source as TypeScript | | unique | false | Drop duplicate values, keeping first occurrence | | fileName | — | Label used for the source (does not change parsing)|

parseStrings(code, { propertyKeys: false, unique: true });

For the ...FromFile helpers, typescript and jsx are inferred from the file extension unless you set them explicitly.

Use from the command line

# Parse a file
node dist/cli.js app.js

# Parse raw source passed inline
node dist/cli.js --code 'const a = "hi"; const o = { "k": 1 };' --detailed

# Parse raw source piped on stdin
cat app.js | node dist/cli.js --pretty
node dist/cli.js --stdin < app.js

# Pretty-print with kind + line/column
node dist/cli.js app.js --detailed --pretty

# Write results to a file, de-duplicated
node dist/cli.js app.js --unique -o strings.json

# Parse a TypeScript source file
node dist/cli.js module.ts --ts

Input precedence is --code, then stdin (--stdin/-/a pipe), then a file path. Run node dist/cli.js --help for the full list, including --no-literals, --no-templates, and --no-property-keys to narrow the scope.

During development you can skip the build step with npm run dev -- app.js.

License

MIT