Package Exports
- trim-margin
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (trim-margin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
trim-margin
trimMargin
like Kotlin and stripMargin
like Scala.
Features
- Indent in a string literal.
- Selectable APIs:
trimMargin
orstripMargin
. - 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`, "#"));
// => "other\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, [delimiter])
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
Indented string.
delimiter
Indent delimiter.
This is used as an argument to a RegExp
object.
defalut: "\\|"
stripMargin(str, [delimiter])
Same trimMargin
.
tm
Use as Tagged template literals.
Same trimMargin(literal)
.
sm
Same tm
.
inject
Inject to string.prototype
: trimMargin
and stripMargin
.
You can use it like method of string type.
injectTrimMargin
Inject to string.prototype
: trimMargin
.
You can use it like method of string type.
injectStripMargin
Inject to string.prototype
: stripMargin
.
You can use it like method of string type.
injectAt(methodName)
Inject to string.prototype
.
You can use it like method of string type.
methodName
Method name injected into string type.
License
MIT © tee-talog