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 🙏

© 2024 – Pkg Stats / Ryan Hefner

dotcjs

v1.0.1

Published

A tool that converts file extensions such as .js or .d.ts to their .cjs and .d.cts counterparts

Downloads

8

Readme

A tool that converts file extensions such as .js or .d.ts to their .cjs and .d.cts counterparts

Description

This is a little tool that simply converts the extensions of filenames such as .js to .cjs, .js.map to .cts.map, .d.ts to .d.cts, and .d.ts.map to .d.cts.map. You might find value in it as part of your build step.

Features

  • Converts .js to .cjs, .js.map to .cts.map, .d.ts to .d.cts, and .d.ts.map to .d.cts.map.
  • Can be used as a CLI
  • Can be used programmatically as a library
  • Is an ESM package with a CommonJS fallback, so you can use it in both types of codebases.

Backers

| | | | | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | BubblesTwitter: @usebubbles | Christopher Blanchard | Ideal Postcodes | Xerox | Trent Raymond | scrubtheweb |

Patreon

Table of Contents

Install

npm

$ npm install dotcjs

Yarn

$ yarn add dotcjs

pnpm

$ pnpm add dotcjs

Run once with npx

$ npx dotcjs

Usage

dotcjs can be used in a variety of ways. The most straightforward usage is directly from the CLI:

CLI usage

You can use this library as a CLI to convert the extensions of files matching an input glob.

The following command renames all files ending with .js, .js.map, .d.ts, and .d.ts.map matched by the glob **/*.* to their respective .cjs counterparts:

dotcjs **/*.*

You can also pass in second argument, outDir, to copy them to a different directory:

dotcjs dist/** dist/cjs

Here's an overview of the options that can be passed via the CLI:

$ dotcjs --help
Usage: dotcjs transform [options] <input> [outDir]

Cconverts file extensions such as .js or .d.ts to their .cjs and .d.cts counterparts based on the input glob

Options:
  -d, --debug [arg]    Whether to print debug information
  -v, --verbose [arg]  Whether to print verbose information
  -s, --silent [arg]   Whether to not print anything
  -c, --cwd [arg]      Optionally which directory to use as the current working directory
  -m, --dry [arg]      If true, no files will be written to disk
  -h, --help           display help for command

You can also just run cjstoesm without explicitly passing in the transform` command, as the CLI defaults to executing that command.

API Usage

You can also use this library programmatically:

import {transform} from "dotcjs";

await transform({
	input: "src/**/*.*"
});

Alternatively, if you don't want the transform function to automatically write files to disk, you can pass write: false as an option and handle it yourself:

import {transform} from "dotcjs";
import fs from "fs";

const result = await transform({
	input: "src/**/*.*",
	write: false
});

// Write to disk
for (const {filename, oldFilename, text} of result.files) {
	fs.copyFileSync(oldFilename, filename);
}

API options

interface TransformOptions {
	/**
	 * The input glob(s) to match against the file system
	 */
	input: string[] | string;
	/**
	 * The output directory to use. If not given, the source files will be overwritten
	 */
	outDir?: string;
	/**
	 * If write is false, no files will be written to disk
	 */
	write?: boolean;
	/**
	 * The FileSystem to use. Useful if you want to work with a virtual file system. Defaults to using the "fs" module
	 */
	fileSystem?: FileSystem;
	/**
	 * A logger that can print messages of varying severity depending on the log level
	 */
	logger?: Loggable;
	/**
	 * The base directory (defaults to process.cwd())
	 */
	cwd?: string;

	/**
	 * If true, debug information will be printed. If a function is provided, it will be invoked for each file name. Returning true from the function
	 * determines that debug information will be printed related to that file
	 */
	debug?: boolean;
}

Contributing

Do you want to contribute? Awesome! Please follow these recommendations.

Maintainers

| | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Frederik WessbergTwitter: @FredWessbergGithub: @wessbergLead Developer |

FAQ

Is this really just an over-engineered mv or cp command?

Yes. It truly is all it is.

License

MIT © Frederik Wessberg (@FredWessberg) (Website)