{"_id":"word-wrapper","_rev":"21-39f1c691bbb80589c695434baaef5505","name":"word-wrapper","description":"wraps words based on arbitrary 2D glyphs","dist-tags":{"latest":"1.0.7"},"versions":{"1.0.0":{"name":"word-wrapper","version":"1.0.0","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"0c8f766793030f5a88811a5d35254651037b6f28","_id":"word-wrapper@1.0.0","_shasum":"95420bccfeb89ec0ec319bfb07cc429be2f146d8","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"95420bccfeb89ec0ec319bfb07cc429be2f146d8","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.0.tgz","integrity":"sha512-0zeaCmuUcIwWPjBzC0HjWCfOD2V+xSj5UeHyXGEc+3AApvyGhDIJ1OdAgR8lKoC16ja0z7Fw6G1dYEMrsr25QA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+q0WCdhAiguqMVqRBhpAOp0/lsf3e5mUrjNwn/Hl82gIgfORnVDl2tUNrfZ82NRYaE1kNzHNLXBZiOgLsgVaFqes="}]}},"1.0.1":{"name":"word-wrapper","version":"1.0.1","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"45fc1ac6c966efe4f703d44012ae24e74661daa2","_id":"word-wrapper@1.0.1","_shasum":"43cbaa1fab914fe2036308027b6c3b1b751aeef3","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"43cbaa1fab914fe2036308027b6c3b1b751aeef3","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.1.tgz","integrity":"sha512-1nMd7VLshM03PWuUd5B8rZeJK/JXaaU3jq6w046fcguAYumFAxRYa5cgaDOIRlHlnfaKuSd/a9/vQV4kF3sVoQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCm6wSkWCu0e/mflryT282TPTWhKZTRCJypQnYUxxg4DgIgb+4m0SEp9p5zA1myhAaUwuMoDSpKaKnfVExP3bAvjUA="}]}},"1.0.2":{"name":"word-wrapper","version":"1.0.2","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"d5d44c55a6e34a347a986d9534002ee9f629414d","_id":"word-wrapper@1.0.2","_shasum":"c664bee905f539ce7e157f308252da98d5cdfd3c","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"c664bee905f539ce7e157f308252da98d5cdfd3c","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.2.tgz","integrity":"sha512-GUYS6EOWFTASvg+y7ofZ648/7a6xgf7GoBbj0ax3J/zmaFaY+zTE5UNmTP31xFwurzPKJTpz0HbYSgW77UDFMw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnjB0V+vA2AIhhWNObdhHyhTFFI2TbZdbXXksUzIr9EgIge2kSfcN++ICH7neFJs4suvn9+UL88KlkGUnT8UMs3XQ="}]}},"1.0.3":{"name":"word-wrapper","version":"1.0.3","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"3865a6803372557bcc626970aea5c8b7694d0dca","_id":"word-wrapper@1.0.3","_shasum":"94926b761371d8c77570df8608e907d89484ad43","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"94926b761371d8c77570df8608e907d89484ad43","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.3.tgz","integrity":"sha512-PgYcfP6i53tXB5AGvmJ8FykjCRD955dUgduvLdVEx/IN2W6LjJW4+0kD0OWCCcSWhh3to8tlPZdISuYzlJxmfQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC8Vibjgfyb2UiuwjSkodefy1KXEC3JyyczBuJ5uytZEAiEAr2RfrJWkUg5A56u5kFOCxol0cgo2R+dHCYNchKJrGUA="}]}},"1.0.4":{"name":"word-wrapper","version":"1.0.4","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"e5605770747215801d48f379fcb85291cb963078","_id":"word-wrapper@1.0.4","_shasum":"433e4ba1c7df628010d40c6e1f197aee1dff7a2d","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"433e4ba1c7df628010d40c6e1f197aee1dff7a2d","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.4.tgz","integrity":"sha512-Qe3tFoC5yB6LMqFO9UVqxpwXdvPaDfuP3IwBlguFxFc4s6T7j9+BizwRQrLOlsXcuU8Xmd614AhkbCQiSzHR9Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDkTZbx/TYr6XrB6JlNEQEnh/MlDE+I1uS0f8zo14LnEAiEAxNDbtza0q04gFfdsTIlcpGxmcLlpwcwoFZvlAwCycuw="}]}},"1.0.5":{"name":"word-wrapper","version":"1.0.5","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"66e71d55359d3e46b0b66171b89ec17b565fbb83","_id":"word-wrapper@1.0.5","_shasum":"7b171cc977119b920d3a98038c92282cbdfbfcb7","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"7b171cc977119b920d3a98038c92282cbdfbfcb7","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.5.tgz","integrity":"sha512-hZwWh9wkHx5z5p6ercKxZ0AfGkj8fCl+oEnkWKy5+0OAsbit7nKe/5ZAvOe5yIZDwcfEykZZ7Ad7uFM8vTY3tg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDultUDT5aBkRIOKSbeTkMrhzsRvN4fHiYudYu573lAXgIhAOeFjUyvOOXR7d/VrSQLSxp4WeQjwkmVhfO1MYJGXGbc"}]}},"1.0.6":{"name":"word-wrapper","version":"1.0.6","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"ee3c25bea27e18abdc1a7626dd640029424db19f","_id":"word-wrapper@1.0.6","_shasum":"a09857ac1c70b0c3bc766c778b2e81e775bf3541","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"a09857ac1c70b0c3bc766c778b2e81e775bf3541","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.6.tgz","integrity":"sha512-KW2So5kXpuegjFkLeU+yMLynQeJ7lhxyVUQ5iA9dS2Xxv/MJKCP2SrcooR0lCBZA3rnCkqtXPcDihnhe/hp+Jg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDglQ62a6RWDD4wvcf8DIXBuz7I/f5CNdcMhnbyv2FzZAIhAK+nnsxuspKyKPfIOF4SyG8Akn/Xb0ZiWouWwMoYYNpB"}]}},"1.0.7":{"name":"word-wrapper","version":"1.0.7","description":"wraps words based on arbitrary 2D glyphs","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{},"devDependencies":{"2d-context":"^1.1.0","6to5ify":"^3.1.2","beefy":"^2.1.1","browserify":"^8.1.0","domready":"^1.0.7","tap-spec":"^2.1.2","tape":"^3.0.3"},"scripts":{"test":"node test.js | tap-spec","canvas":"beefy demo/canvas.js -- -t 6to5ify","build":"browserify demo/canvas.js -t 6to5ify > demo/bundle.js"},"keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"homepage":"https://github.com/mattdesl/word-wrapper","bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"gitHead":"04637065d57a8690d98a870fd3b69a89f63d6e0e","_id":"word-wrapper@1.0.7","_shasum":"1f14afebf66dfdf0fef55efd37184efbd08c28b6","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"dist":{"shasum":"1f14afebf66dfdf0fef55efd37184efbd08c28b6","tarball":"https://registry.npmjs.org/word-wrapper/-/word-wrapper-1.0.7.tgz","integrity":"sha512-VOPBFCm9b6FyYKQYfn9AVn2dQvdR/YOVFV6IBRA1TBMJWKffvhEX1af6FMGrttILs2Q9ikCRhLqkbY2weW6dOQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAWwt7oBssmxh6mYBlykyFOgRNOdraE+ZaNSeR1eI2mNAiEAn48n9OtrlNeKl5j7ZlMdeFx7r9g90btJ9T2mc20Hy44="}]}}},"readme":"# word-wrapper\n\n[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)\n\n![img](http://i.imgur.com/LqQyHSg.png)\n\n<sup>click [here](http://mattdesl.github.io/word-wrapper/demo/) for a Canvas demo</sup>\n\nThis is a generic word wrapper for left-to-right text in 2D applications. It can be used in console, canvas, WebGL, etc. Accepts a custom `measure` function for glyph metrics. \n\nThe simplest use-case:\n\n```js\nvar text = wrap('the quick brown fox jumps over the lazy dog', { width: 8 })\nconsole.log(text)\n``` \n\nThis will print the following:\n\n```\nthe\nquick\nbrown\nfox\njumps\nover the\nlazy dog\n```\n\nIn 2D applications it's more common to layout the text manually. For this we can use `wrap.lines()` to operate on a list of `{ start, end }` indices. Then each line can be rendered with `text.substring(line.start, line.end)`. An example:\n\n```js\n//for example...\nvar lines = wrap.lines(text, { width: 40 })\n\n//operate on the lines...\nvar text = lines\n        .map( x => text.substring(x.start, x.end) )\n        .join('\\n')\n```\n\nSee [demo/canvas](demo/canvas.js) for a full 2D example.\n\n## Usage\n\n[![NPM](https://nodei.co/npm/word-wrapper.png)](https://www.npmjs.com/package/word-wrapper)\n\n#### `text = wordwrap(text[, opt])`\n\nWord-wraps the `text` string with the given options. Returns a string with the word-wrapped result.\n\n- `start` the starting index to word-wrap, default 0\n- `end` the ending index to word-wrap (exclusive), default `text.length`\n- `width` the width to word wrap to, in 'units' (see below)\n- `measure` a function that measures the number of glyphs that can fit in (see [measure](#measure)). Defaults to monospace (i.e. 1 char is 1 unit)\n- `mode` can be 'pre' (maintain spacing), or 'nowrap' (collapse whitespace but only break on newline characters), otherwise assumes normal word-wrap behaviour\n\nThe `width` is measured in 'units' which could be pixels, centimeters, characters, etc. By default, one \"unit\" corresponds to one character (i.e. for monospace console rendering). To wrap text to a pixel width, you should use a custom [measure](#measure) function.\n\nIf mode is `\"pre\"` and `width` is specified, it will clip the characters to the given width (to avoid them over-flowing outside the bounds). \n\n#### `lines = wordwrap.lines(text[, opt])`\n\nTakes the same parameters as the above method, but returns a list of \"lines\" objects for manual text layout/rendering. A \"line\" is typically an object with `{ start, end }` indices that can be used with `text.substring(start, end)`. The \"line\" is the return value from the `measure` function, so it may also include application-specific data (i.e. to avoid re-computing line widths).\n\n## measure\n\nTo layout glyphs in 2D space, you typically will need to measure the width of each glyph (and its x-advance, kerning, etc) to determine the maximum number of glyphs that can fit within a specified *available width*. \n\nYou can pass a custom `measure` function which takes the text being wrapped, the `start` (inclusive) and `end` (exclusive) indices into the string, and the desired `width`. The return value should be an object with `{ start, end }` indices, representing the actual glyphs that can be rendered within those bounds. \n\nFor example, a Canvas2D implementation that uses monospace fonts might look like this:\n\n```js\n//the canvas font style\nvar font = '24px \"Courier New\", monospace'\n\n//compute width\nvar measure = createMetrics(context, font)\n\nfunction createMetrics(context, font) {\n    context.font = font\n    var charWidth = context.measureText('M').width\n\n    return function measure(text, start, end, width) {\n        //measures the chunk of text, returning the substring\n        //we can fit within the given width\n        var availableGlyphs = Math.floor(width/charWidth)\n        var totalGlyphs = Math.floor((end-start)*charWidth)\n        var glyphs = Math.min(end-start, availableGlyphs, totalGlyphs)\n        return {\n            start: start,\n            end: start+glyphs\n        }\n    }\n}\n\nfunction draw(context) {\n    var lines = wordwrap(text, { measure: measure, width: 200 })\n\n    //draw the lines.. \n}\n```\n\n## License\n\nThe original implementation is based on [LibGDX's word wrapper](http://libgdx.badlogicgames.com/).\n\nMIT, see [LICENSE.md](http://github.com/mattdesl/word-wrapper/blob/master/LICENSE.md) for details.\n","maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"time":{"modified":"2022-06-29T03:11:36.195Z","created":"2015-01-11T20:50:36.894Z","1.0.0":"2015-01-11T20:50:36.894Z","1.0.1":"2015-01-11T20:51:35.743Z","1.0.2":"2015-01-11T20:51:44.526Z","1.0.3":"2015-01-11T20:55:31.158Z","1.0.4":"2015-01-11T20:56:00.753Z","1.0.5":"2015-01-11T21:04:24.696Z","1.0.6":"2015-01-11T23:00:45.613Z","1.0.7":"2015-01-11T23:01:50.894Z"},"homepage":"https://github.com/mattdesl/word-wrapper","keywords":["glyph","word","wrap","wordwrap","pre","string","text","font","rendering","canvas","2d","text"],"repository":{"type":"git","url":"git://github.com/mattdesl/word-wrapper.git"},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"bugs":{"url":"https://github.com/mattdesl/word-wrapper/issues"},"license":"MIT","readmeFilename":"README.md","users":{"rchiniquy":true,"hellopath":true,"mikkoh":true}}