Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartwrap is not as smart as breakword #5

Closed
mscalora opened this issue Feb 14, 2020 · 0 comments
Closed

smartwrap is not as smart as breakword #5

mscalora opened this issue Feb 14, 2020 · 0 comments

Comments

@mscalora
Copy link
Contributor

smartwrap is not able to break words as well as breakword

I think maybe there is some use of .split() and/or .substr() that needs to be changed to arrays created with the spread operator [...str] which knows how to correctly divide strings to characters

See output from:

const breakword = require("breakword")

const str = "😀😀😀😀"

console.log(`String: ${str}`)
for (let w = 0; w < 10; w++) {
  let x = breakword(str,w),
    part1 = [...str].slice(0, x + 1).join(""),
    part2 = [...str].slice(x + 1).join("")

  console.log(`w=${w} bw=${x} "${part1}"   "${part2}"`)
}

const smartwrap = require("smartwrap")

console.log(`String: ${str}`)
for (let w = 0; w < 10; w++) {
  let wrapped = smartwrap(str, {width: w, breakword: true, errorChar: "é"}),
    lines = wrapped.split("\n"),
    part1 = lines[0],
    part2 = lines[1] || null

  console.log(`lines=${lines.length} ${JSON.stringify(part1)}   ${JSON.stringify(part2)}`)
}
@tecfu tecfu closed this as completed in 2bcd028 Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant