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

@bemoje/tscode

v2.0.0

Published

TypeScript code processing utilities and AST helpers for imports, formatting, and linting.

Readme

@mono/tscode

TypeScript code processing utilities and AST helpers for imports, formatting, and linting.

TypeScript Module

Exports

  • importStatementGetKeywords.
  • importStatementHasTypeKeyword: Checks if an import statement line contains the 'type' keyword.
  • importStatementStripKeywords: Removes the 'import' and 'type' keywords from an import statement line.
  • importStatementToFormattedOneLiner: Converts a multi-line import statement to a formatted single line with proper spacing. Adds spaces around braces, keywords, and other import statement elements for readability.
  • importStatementToOneLiner: Converts a multi-line import statement to a single line by removing comments and extra whitespace. This function strips comments, normalizes whitespace, and removes trailing commas to create a clean single-line import statement.
  • parseImportStatement: Parses an import statement into its constituent parts for detailed analysis. This function breaks down an import statement into keywords, specifiers, module path, and other components, providing a comprehensive analysis of the import structure.
  • tsCrlfToLf for consistent processing across different operating systems.
  • tsExtractImports: Extract all import statements from a given TypeScript source code string. This function parses TypeScript code to identify and extract all import statements, handling both single-line and multi-line imports. It correctly ignores import-like text within comments and string literals.
  • tsLintFilepath: Runs ESLint with auto-fix on a TypeScript file, suppressing any errors. This function attempts to automatically fix linting issues in the specified file using ESLint's auto-fix capability. Any errors during execution are silently ignored.
  • tsSortImports: Sorts import statements in TypeScript code alphabetically by module specifier. This function extracts all import statements, sorts them alphabetically by the module path, and reconstructs the code with sorted imports at the top.
  • tsStripImports: Removes import statements from TypeScript code. This function extracts all import statements and removes them from the source code, leaving only the non-import content.

Usage

Import Parsing & Manipulation

import {
  parseImportStatement,
  importStatementGetKeywords,
  importStatementHasTypeKeyword,
  importStatementStripKeywords,
  tsExtractImports,
  tsStripImports,
  tsSortImports,
} from '@mono/tscode'

const importStr = "import type { A, B } from 'module'"

// Parse into structured data
const parsed = parseImportStatement(importStr)

// Check properties
importStatementHasTypeKeyword(importStr)
// => true

// Get named imports/exports keywords
importStatementGetKeywords(importStr)
// => ['A', 'B']

// Remove properties
importStatementStripKeywords(importStr, ['B'])
// => "import type { A } from 'module'"

// Find all import statements in a file
const sourceCode = `
import { X } from 'x'
const y = 1;
`
tsExtractImports(sourceCode)
// => ["import { X } from 'x'"]

// Strip imports from source code
tsStripImports(sourceCode)
// => "\nconst y = 1;\n"

// Sort imports in source code alphabetically
tsSortImports(sourceCode)

Import Formatting

import { importStatementToOneLiner, importStatementToFormattedOneLiner } from '@mono/tscode'

const multiLine = `import {
  A,
  B
} from 'm'`

importStatementToOneLiner(multiLine)
// => "import { A, B } from 'm'"

importStatementToFormattedOneLiner(multiLine)
// => "import { A, B } from 'm'"

Formatting Utilities

import { tsCrlfToLf, tsLintFilepath } from '@mono/tscode'

// Normalize line endings
tsCrlfToLf('line1\r\nline2')
// => 'line1\nline2'

// Applies basic fixes to a filepath specific to ts files if applicable
tsLintFilepath('path/to/file.tsx')