Socket
Socket
Sign inDemoInstall

indent-string

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

indent-string

Indent each line in a string


Version published
Maintainers
1
Weekly downloads
39,504,159
increased by5.22%

Weekly downloads

Package description

What is indent-string?

The indent-string npm package is a utility that allows users to add indentation to the beginning of each line in a string. This can be particularly useful for formatting multi-line strings or code snippets in a more readable manner. The package provides a simple interface to specify the number of spaces or the string to use for indentation, making it a versatile tool for text manipulation in Node.js applications.

What are indent-string's main functionalities?

Indenting with spaces

This feature allows you to indent each line of a given string with a specified number of spaces. In the code sample, the string 'Unicorn\nRainbow' is indented by 4 spaces.

const indentString = require('indent-string');

console.log(indentString('Unicorn\nRainbow', 4));
// Output:
//     Unicorn
//     Rainbow

Indenting with custom string

This feature enables indenting each line of a string with a custom string instead of spaces. In the example, the string 'Unicorn\nRainbow' is indented using the '♥' character, repeated 4 times as specified.

const indentString = require('indent-string');

console.log(indentString('Unicorn\nRainbow', 4, {indent: '♥'}));
// Output:
// ♥♥♥♥Unicorn
// ♥♥♥♥Rainbow

Other packages similar to indent-string

Readme

Source

indent-string

Indent each line in a string

Install

$ npm install indent-string

Usage

import indentString from 'indent-string';

indentString('Unicorns\nRainbows', 4);
//=> '    Unicorns\n    Rainbows'

indentString('Unicorns\nRainbows', 4, {indent: '♥'});
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'

API

indentString(string, count?, options?)

string

Type: string

The string to indent.

count

Type: number
Default: 1

How many times you want options.indent repeated.

options

Type: object

indent

Type: string
Default: ' '

The string to use for the indent.

includeEmptyLines

Type: boolean
Default: false

Also indent empty lines.

  • indent-string-cli - CLI for this module
  • strip-indent - Strip leading whitespace from every line in a string

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 17 Apr 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc