Socket
Socket
Sign inDemoInstall

dprint-node

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dprint-node

A node API for the dprint TypeScript and JavaScript code formatter


Version published
Maintainers
1
Created

What is dprint-node?

dprint-node is a Node.js wrapper for the dprint code formatting tool. It allows developers to format code using dprint's powerful and extensible formatting capabilities directly within a Node.js environment.

What are dprint-node's main functionalities?

Format Code

This feature allows you to format code using dprint. In this example, TypeScript code is formatted to follow dprint's formatting rules.

const dprint = require('dprint-node');

const code = 'function helloWorld() {console.log("Hello, world!");}';
const formattedCode = dprint.format('typescript', code);
console.log(formattedCode);

Configure Formatter

This feature allows you to configure the formatter with custom settings. In this example, the TypeScript formatter is configured to use a line width of 80 characters and spaces instead of tabs.

const dprint = require('dprint-node');

const config = {
  'typescript': {
    'lineWidth': 80,
    'useTabs': false
  }
};
const code = 'function helloWorld() {console.log("Hello, world!");}';
const formattedCode = dprint.format('typescript', code, config);
console.log(formattedCode);

Format Multiple Files

This feature allows you to format multiple files. In this example, it reads TypeScript files, formats them, and writes the formatted code back to the files.

const dprint = require('dprint-node');
const fs = require('fs');

const files = ['file1.ts', 'file2.ts'];
files.forEach(file => {
  const code = fs.readFileSync(file, 'utf8');
  const formattedCode = dprint.format('typescript', code);
  fs.writeFileSync(file, formattedCode);
});

Other packages similar to dprint-node

FAQs

Package last updated on 15 Sep 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc