Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dedent

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dedent - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

36

dedent.js
"use strict";
function dedent() {
var strings = arguments[0];
var result = "";
for (var i = 0; i < strings.length; i++) {
var next = strings.raw[i].
replace(/\\\n[ \t]*/g, "").
replace(/\n[ \t]*/g, "\n");
result += next;
if (i + 1 < arguments.length) {
result += arguments[i + 1];
function dedent(strings, ...values) {
// first, perform interpolation
let result = "";
for (let i = 0; i < strings.length; i++) {
// join lines when there is a suppressed newline
result += strings.raw[i].replace(/\\\n[ \t]*/g, "");
if (i < values.length) {
result += values[i];
}
}
return result;
// now strip indentation
let lines = result.trim().split("\n");
let mindent = null;
lines.forEach(l => {
if (m = l.match(/^ +/)) {
let indent = m[0].length;
if (!mindent) {
// this is the first indented line
mindent = indent;
} else {
mindent = Math.min(mindent, indent);
}
}
});
if (mindent === null) return result;
return lines.map(l => l[0] === " " ? l.slice(mindent) : l).join("\n");
};
module.exports = dedent;
{
"name": "dedent",
"version": "0.1.1",
"version": "0.2.0",
"description": "An ES6 string tag that strips indentation from multi-line strings",

@@ -5,0 +5,0 @@ "main": "dedent.js",

@@ -11,12 +11,39 @@ # Dedent

function usageExample() {
return dd`A string that gets so long you need to break it over multiple
lines. Luckily dedent is here to keep it readable without lots of
spaces ending up in the string itself.`;
let first = dd`A string that gets so long you need to break it over multiple
lines. Luckily dedent is here to keep it readable without
lots of spaces ending up in the string itself.`;
let second = dd`
Leading and trailing lines will be trimmed, so you can write something like
this and have it work as you expect:
* how convenient it is
* that I can use an indented list
- and still have it do the right thing
That's all.
`;
return first + "\n\n" + second;
}
```
usageExample().indexOf(' '); //=> -1
```
> console.log(usageExample());
A string that gets so long you need to break it over multiple
lines. Luckily dedent is here to keep it readable without
lots of spaces ending up in the string itself.
Leading and trailing lines will be trimmed, so you can write something like
this and have it work as you expect:
* how convenient it is
* that I can use an indented list
- and still have it do the right thing
That's all.
```
## License
MIT
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