indentjs / endent Goto Github PK
View Code? Open in Web Editor NEW⬅️ An ES6 string tag makes indentation better
⬅️ An ES6 string tag makes indentation better
The compiled Javascript output must use require and not import, since the import is not yet supported in Node.js properly.
This is happening, coz you are using esnext
for the module property inside the tsconfig.json
file.
Mind fixing it and push a new release?
If I do this:
console.log(endent`
hello
\`\`\`json
${endent.pretty({ a: 1, b: 2, c: { foo: 3, bar: 4 } })}
\`\`\`
world
`)
Or this:
const myJson = JSON.stringify({ a: 1, b: 2, c: { foo: 3, bar: 4 } })
console.log(endent`
hello
\`\`\`json
${myJson}
\`\`\`
world
`)
I get this poorly-formatted output:
hello
```json
{
"a": 1,
"b": 2,
"c": {
"foo": 3,
"bar": 4
}
}
```
world
But I expect this:
hello
```json
{
"a": 1,
"b": 2,
"c": {
"foo": 3,
"bar": 4
}
}
```
world
However, if I put some text before my object:
console.log(endent`
hello
\`\`\`json
REMOVE_ME${endent.pretty({ a: 1, b: 2, c: { foo: 3, bar: 4 } })}
\`\`\`
world
`)
It formats everything correctly (but then I need to remove the REMOVE_ME
bit in a separate step):
hello
```json
REMOVE_ME{
"a": 1,
"b": 2,
"c": {
"foo": 3,
"bar": 4
}
}
```
world
I was going to file this over at https://github.com/zhouhanseng/endent but you have issues disabled there.
endent
throws with the following code:
var endent = require("endent")
const a = '"test"';
console.log(endent`
{
${a}: null
}
`);
https://runkit.com/embed/dc58pgajgtpl
The line throwing the error:
Line 29 in 2ffcf9a
We hit a problem that we think is related to endent
on Windows with regard to printing something like foo\\node_modules
where the line break should be escaped but then isn't
Details here graphql-nexus/nexus-prisma#50.
Currently endent trims all start and end newlines. But it would be more flexible to only trim max 1 newline. This way we can create newlines in the template string. Problem is that the logic is in dedent and my PR is not getting merged. Also, I don't know what the state of the project is. Maybe some feedback here how to proceed. Here is the link to my PR in dedent:
Given that
endent`
foo.
${"hello\nworld"}
bar.
`
correctly comes out as
foo.
hello
world
bar.
I expect this:
endent`
foo.
x=${"hello\nworld"}
bar.
`
to come out as
foo.
x=hello
bar
bar.
but instead it comes out as
foo.
x=hello
world
bar.
and when I try to add the spaces on the second line myself
endent`
foo.
x=${"hello\n world"}
bar.
`
then it comes out even worse
foo.
x=hello
world
bar.
endent
depends on objectorarray
which has an error in its package.json, it declares "main": "dist/index.js"
but the package published on npm does not contain a /dist
folder:
This is causing all sorts of issues with endent
.
For example, if you try to compile an app containing endent
with Rollup or Vite, the build command will fail with this error:
[commonjs] Failed to resolve entry for package "objectorarray". The package may have incorrect main/module/exports specified in its package.json
Node.js 16 is also showing a warning with a similar content:
DeprecationWarning: Invalid 'main' field in '\node_modules\objectorarray\package.json' of 'dist/index.js'
I'm opening an issue here because I believe that @zhouhanseng is one of the authors of both endent
and objectorarray
.
There are two open issues (issue 3 and issue 7) about this in the objectorarray
repo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.