Socket
Socket
Sign inDemoInstall

trim-margin

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

trim-margin

"trimMargin" like Kotlin and "stripMargin" like Scala.


Version published
Maintainers
1
Weekly downloads
1,013
decreased by-4.07%

Weekly downloads

Readme

Source

trim-margin

Build Status

trimMargin like Kotlin and stripMargin like Scala.

NPM

Features

  • Indent in a string literal.
  • Selectable APIs: trimMargin or stripMargin.
  • Use as tagged template literals.
  • Inject to string type.

install

$ npm i -S trim-margin

Usage

const {
    trimMargin,
    tm,
    inject,
} = require("trim-margin");

console.log(trimMargin(`
	|trim
    | indent
        | spaces`));
// => "\ntrim\n indent\n spaces"

console.log(trimMargin(`
    #other
    # delimiter`, "#"));
// => "\nother\n delimiter"

const template = `    | template`;
const literal  = `    | literal`;
console.log(tm`\
    |tagged
    ${template}
    |${literal}`);
// => "tagged\n template\n    | literal"

inject();
console.log(`\
    |inject
 to | string`.trimMargin());
// => "inject\n to | string"

API

trimMargin(str: string, [delimiter: string]): string

Trim indent spaces.

More detail "spaces":

Matches a single character other than white space. Equivalent to [^ \f\n\r\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff].

From: MDN web docs

Expect, /\r?\n/

str: string

Indented string.

delimiter: string

Indent delimiter. This is used as an argument to a RegExp object. defalut: "\\|"

stripMargin(str: string, [delimiter :string]): string

Same trimMargin.

tm

Use as Tagged template literals. Same trimMargin(literal).

sm

Same tm.

inject: void

Inject to String: trimMargin and stripMargin. You can use it like method of string type.

injectTrimMargin: void

Inject to String: trimMargin. You can use it like method of string type.

injectStripMargin: void

Inject to String: stripMargin. You can use it like method of string type.

injectAt(methodName: string): void

Inject to String. You can use it like method of string type.

methodName: string

Method name injected into string type.

License

MIT © tee-talog

Keywords

FAQs

Last updated on 29 May 2019

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