{"_id":"wcstring","_rev":"10-e83992e21afd9b5f168629fec6b7b4c2","name":"wcstring","time":{"modified":"2022-06-28T22:23:04.741Z","created":"2015-10-31T20:08:00.449Z","1.0.0":"2015-10-31T20:08:00.449Z","1.0.1":"2015-10-31T20:12:12.753Z","2.0.0":"2015-11-02T22:47:05.937Z","2.0.1":"2015-11-05T03:44:07.402Z","2.1.0":"2015-11-05T04:59:28.642Z","2.1.1":"2016-05-02T12:59:28.709Z"},"maintainers":[{"name":"leichtgewicht","email":"mh@leichtgewicht.at"}],"dist-tags":{"latest":"2.1.1"},"description":"Terminal string based on wcsize","readme":"[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg?style=flat)](LICENSE.md)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\n[![npm version](https://badge.fury.io/js/wcstring.svg)](https://badge.fury.io/js/wcstring)\n[![Build Status](https://travis-ci.org/martinheidegger/wcstring.svg?branch=master)](https://travis-ci.org/martinheidegger/wcstring)\n\n# wcstring\n`wcstring` is a JavaScript CommonJS (node.js) package for working\nwith strings in a terminal (tty) context. In the terminal various characters\nare double the size of others, to operate on those characters `wcstring` is a helpful companion.\n\n## Installation & Usage\nWith [npm](https://docs.npmjs.com/getting-started/installing-node) you can install and use the `wcstring` like this:\n\n```\n$ npm install wcstring --save\n```\n\nWith the package being successfully installed you can create an instance like this:\n\n```JavaScript\nvar WCString = require('wcstring')\nvar str = new WCString('ABCdef', charWidth)\nvar str2 = WCString('abcDEF', charWidth) // You don't need to use `new`\n```\n\n## Operations\nOn the instance you can apply a set of operations. Note that the following explanation uses `size` as an accumulated amount of width and `width` as a single-line `size`.\n\n### `.width()`\nGet the `size` of the widest line in the string. \n\n### `.size()`\nGet the `size` of the complete string.\n\n### `.sizeBeforeFirst(search, [<int> startOffset])`\nAnalogous to [`String.indexOf`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf). Looks for the first occurance of `search`. Optionally takes `startOffset` which is the `size` of characters that have to happen before the search takes place (default=0).\n\n### `.sizeBeforeLast(search, [<int> endOffset])`\nAnalogous to [`String.lastIndexOf`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf). Looks for the last occurance of `search`.\nOptionally takes `endOffset` which is the size offset from the end of the string from which to search for `search`.\n\n### `.substring(<int> startSize, [<int> endSize])`\nAnalogous to [`String.substring`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring). This method will return the **fully visible** characters between `startSize` and `endSize`. If `endSize` is not given it will assume a substring from `startSize` until the end of the string.\n_However:_ **Unlike** `String.substring`, this method returns an object with the properties `size` and `string` in order to know the size of the substring.\n\nExample:\n```JavaScript\nvar vsstring = require('wcstring')\nvsstring('abcdef', charWidth).substring(0, 3) // {string: 'abc', size: 2.4}\n```\n\n### `.substr(<int> startSize, [<int> size])`\nEqual to `.substring(startSize, startSize + size)`.\n\n### `.wrap(<int> width, [padding])`\nNormalizes the string in order for all lines to fit within `width`.\n\nExample:\n```JavaScript\nvar vsstring = require('wcstring')\nvsstring('abcdef', charWidth).wrap(3) // 'abc\\ndef'\nvsstring('ab cd ef', charWidth).wrap(5) // 'ab cd\\nef'\nvsstring('ab cd ef', charWidth).wrap(3) // 'ab\\ncd\\nef'\n```\n\n#### Padding\nThe padding option takes a padding specification and applies it to the\nwrapping process.\n\nExample:\n\n```JavaScript\nvar padding = {\n    first: {left: ' - ', right: ' '},\n    regular: {left: '   ', right: ' '}\n}\nvsstring('abcdefghijklmnop', charWidth).wrap(10, padding)\n//  - abcdef\n//    ghijkl\n//    mnop\n```\n\nThere are a few shorthands to specifying the padding:\n\n```JavaScript\npadding = '  '\n```\n\n... is equals to ...\n\n```JavaScript\n{\n    first: '  ',\n    regular: '  '\n}\n```\n\n... is equals to ...\n\n```JavaScript\n{\n    first: {left: '  ': right: undefined},\n    regular: {left: '  ': right: undefined}\n}\n```\n\nAlso you can preset left/right for both first and regular:\n\n```JavScript\n{\n    right: 'x',\n    first: {left: ' - '},\n    regular: {left: '   '}\n}\n```\n\n... is equal to ... \n\n```JavaScript\n{\n    first: {left: ' - ', right: 'x'},\n    regular: {left: '   ', right: 'x'}\n}\n```\n\nNote that the left/right presets override the first/regular specification:\n\n```JavaScript\n{\n    left: 'x',\n    first: '-',\n    regular: ' '\n}\n```\n\n... is equal to ...\n\n```JavaScript\n{\n    first: {left: 'x', right: undefined},\n    regular: {left: 'x', right: undefined}\n}\n```\n\nAlso it supports a fallback to regular if first is missing:\n\n```JavaScript\n{\n    regular: {left: 'x', right: undefined}\n}\n```\n\n... is equal to ...\n\n```JavaScript\n{\n    first: {left: 'x', right: undefined},\n    regular: {left: 'x', right: undefined}\n}\n```\n\n### `wcstring.padding([process], [width], padding)`\nTurns a flexible padding definition into a clear padding definition. You can pass in an optional `process` variable to process the strings before they are being turned into wcstrings. You can also pass-in a `width` to make sure that the padding will not exceed the width of, say, a wrapped string.\n\n### `.truncate(<int> size, <wcstring || String> suffix)`\nTruncates the string after a size. Will append the given `suffix` to the string if it does exceed the size.\n\n### `.pop()`\nRemoves the last character from the string and returns the new `.size()`.\n","versions":{"1.0.1":{"name":"wcstring","version":"1.0.1","description":"Terminal string based on wcsize","main":"index.js","directories":{"test":"test"},"scripts":{"test":"tape test/**/*.js; standard"},"keywords":["unicode","visualwidth","terminal","wide character","wc","wide character string","wcs","terminal","width","wcwidth","wcswidth"],"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"license":"ISC","devDependencies":{"istanbul":"^0.4.0","standard":"^5.3.1","tape":"^4.2.2"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/wcstring.git"},"bugs":{"url":"https://github.com/martinheidegger/wcstring/issues"},"homepage":"https://github.com/martinheidegger/wcstring#readme","dependencies":{"varsize-string":"^1.0.0","wcsize":"^1.0.0"},"gitHead":"d2c60a5cbbc86e4198bff9f505c560f62667325c","_id":"wcstring@1.0.1","_shasum":"8c0a8f218f2968ef76e0379c70c56ddb4776c999","_from":".","_npmVersion":"3.3.9","_nodeVersion":"4.2.1","_npmUser":{"name":"leichtgewicht","email":"mh@leichtgewicht.at"},"maintainers":[{"name":"leichtgewicht","email":"mh@leichtgewicht.at"}],"dist":{"shasum":"8c0a8f218f2968ef76e0379c70c56ddb4776c999","tarball":"https://registry.npmjs.org/wcstring/-/wcstring-1.0.1.tgz","integrity":"sha512-XowGjzDYgRxcxsj1kKGCZGPyjVvZJZINR0z0MBoccJBHI5i0JWTXFsIzdLs7ykqN8NqFF6e1NnFdtHJ0yhOS7w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC1QFV2I9Wq1cmqpELUMJ6yw5kdaa9FtXiLspmSKBd8qAiEAl2TZFmZgMXQTkiQdy+ztNf2kX+jtMhf/fyHpqhuz1DQ="}]}},"2.0.0":{"name":"wcstring","version":"2.0.0","description":"Terminal string based on wcsize","main":"index.js","directories":{"test":"test"},"scripts":{"test":"istanbul cover tape test/**/*.js && standard"},"keywords":["unicode","visualwidth","terminal","wide character","wc","wide character string","wcs","terminal","width","wcwidth","wcswidth"],"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"license":"ISC","devDependencies":{"istanbul":"^0.4.0","standard":"^5.3.1","tape":"^4.2.2"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/wcstring.git"},"bugs":{"url":"https://github.com/martinheidegger/wcstring/issues"},"homepage":"https://github.com/martinheidegger/wcstring#readme","dependencies":{"varsize-string":"^2.0.1","wcsize":"^1.0.0"},"gitHead":"90d220a06c435ee591b06569620baa0119c108fa","_id":"wcstring@2.0.0","_shasum":"729b5fd0e454bc6b685791ece954904196724270","_from":".","_npmVersion":"3.3.9","_nodeVersion":"4.2.1","_npmUser":{"name":"leichtgewicht","email":"mh@leichtgewicht.at"},"maintainers":[{"name":"leichtgewicht","email":"mh@leichtgewicht.at"}],"dist":{"shasum":"729b5fd0e454bc6b685791ece954904196724270","tarball":"https://registry.npmjs.org/wcstring/-/wcstring-2.0.0.tgz","integrity":"sha512-Y4Gk8r0Kz2E9ES0Qre0cRqimgiRCtIolNAiByOKISmth3IBIrb93K2yRWqUx8CtHAQZo+dgrRqVDqHzTnsZJcg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCgcpLUnTk37jE8nxTof8TXi5lAeYr6pkQZ8B8VEDX+kAIgRzyUOEaYQniND6USTkRzL8yc8J/JMvZIhWy3oDJE9cI="}]}},"2.0.1":{"name":"wcstring","version":"2.0.1","description":"Terminal string based on wcsize","main":"index.js","directories":{"test":"test"},"scripts":{"test":"istanbul cover tape test/**/*.js && standard"},"keywords":["unicode","visualwidth","terminal","wide character","wc","wide character string","wcs","terminal","width","wcwidth","wcswidth"],"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"license":"ISC","devDependencies":{"istanbul":"^0.4.0","standard":"^5.3.1","tape":"^4.2.2"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/wcstring.git"},"bugs":{"url":"https://github.com/martinheidegger/wcstring/issues"},"homepage":"https://github.com/martinheidegger/wcstring#readme","dependencies":{"varsize-string":"^2.1.1","wcsize":"^1.0.0"},"gitHead":"5aa20b8872b4b1f95b12d9a8954f4a81e8f2d17b","_id":"wcstring@2.0.1","_shasum":"1cbc21d5c7c87332bb5e0b8c75ff5aa33f63fada","_from":".","_npmVersion":"3.3.9","_nodeVersion":"4.2.1","_npmUser":{"name":"leichtgewicht","email":"mh@leichtgewicht.at"},"maintainers":[{"name":"leichtgewicht","email":"mh@leichtgewicht.at"}],"dist":{"shasum":"1cbc21d5c7c87332bb5e0b8c75ff5aa33f63fada","tarball":"https://registry.npmjs.org/wcstring/-/wcstring-2.0.1.tgz","integrity":"sha512-6mDSIwWnxRhV3ylSWnISj4yNsKoaCvzK923zN5UsIBcXhmd/9YmFuNfRr5VVThHFyhq4vrqwgEcBcpNGXosRiQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD0V6n1gXuIgl6a1O+Nq0xiveaxtl3eYoPxpIEKOm9GSAIhAKzfX00nffQ27ruJQXsQRvPJ6QwNOx+YBmE03efw+6bO"}]}},"2.1.0":{"name":"wcstring","version":"2.1.0","description":"Terminal string based on wcsize","main":"index.js","directories":{"test":"test"},"scripts":{"test":"istanbul cover tape test/**/*.js && standard"},"keywords":["unicode","visualwidth","terminal","wide character","wc","wide character string","wcs","terminal","width","wcwidth","wcswidth"],"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"license":"ISC","devDependencies":{"istanbul":"^0.4.0","standard":"^5.3.1","tape":"^4.2.2"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/wcstring.git"},"bugs":{"url":"https://github.com/martinheidegger/wcstring/issues"},"homepage":"https://github.com/martinheidegger/wcstring#readme","dependencies":{"varsize-string":"^2.2.0","wcsize":"^1.0.0"},"gitHead":"ebf99d8cba475aa2d52cde10f8fd5e6c2d850cb2","_id":"wcstring@2.1.0","_shasum":"f0de64b00502ac2eb361c9ac106a784ed1ec711c","_from":".","_npmVersion":"3.3.9","_nodeVersion":"4.2.1","_npmUser":{"name":"leichtgewicht","email":"mh@leichtgewicht.at"},"maintainers":[{"name":"leichtgewicht","email":"mh@leichtgewicht.at"}],"dist":{"shasum":"f0de64b00502ac2eb361c9ac106a784ed1ec711c","tarball":"https://registry.npmjs.org/wcstring/-/wcstring-2.1.0.tgz","integrity":"sha512-kE5rG9BlPbriicdpOpxigcNbt0wufcVnLOlXdSGGE3nI9UQ4qhGSvtCyFrx/UFbTqAHK1KPsfZMScjSHB/JiMA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC+3Q7XFaXUfLQzBa8GFWaw9T08JbnFSiLxzhnQxspptwIhAOQ+zKX10xq6sH9ULHnVDHP3GlqsT42Y1/eG6ZxqnGCi"}]}},"2.1.1":{"name":"wcstring","version":"2.1.1","description":"Terminal string based on wcsize","main":"index.js","directories":{"test":"test"},"scripts":{"test":"istanbul cover tape test/**/*.js && standard"},"keywords":["unicode","visualwidth","terminal","wide character","wc","wide character string","wcs","terminal","width","wcwidth","wcswidth"],"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"license":"ISC","devDependencies":{"istanbul":"^0.4.0","standard":"^5.3.1","tape":"^4.2.2"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/wcstring.git"},"bugs":{"url":"https://github.com/martinheidegger/wcstring/issues"},"homepage":"https://github.com/martinheidegger/wcstring#readme","dependencies":{"varsize-string":"^2.2.1","wcsize":"^1.0.0"},"gitHead":"24358dd59c46b26f1b899bb1529a352b18bd86e8","_id":"wcstring@2.1.1","_shasum":"ded52d745c9c71e24d0a489d2826d22a365ed067","_from":".","_npmVersion":"3.8.3","_nodeVersion":"5.10.0","_npmUser":{"name":"leichtgewicht","email":"martin.heidegger@gmail.com"},"dist":{"shasum":"ded52d745c9c71e24d0a489d2826d22a365ed067","tarball":"https://registry.npmjs.org/wcstring/-/wcstring-2.1.1.tgz","integrity":"sha512-81yoFUY/2Fw4RFzIkrlC47g7023/XkKofj62CNFT1kdZn6z7o2xhz8ffR7Wat76SuJTmrFNLmGDd7FLaZsIo5A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFCIB4Ai1p7rYnyus2oDMVE7rwhO2TL8qam9OaxGygCNAiEA2KoVCwbG5xgZ9Viwq8BF1pUT6JdKo6aRcZQTqrCn344="}]},"maintainers":[{"name":"leichtgewicht","email":"mh@leichtgewicht.at"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/wcstring-2.1.1.tgz_1462193966750_0.6065537608228624"}}},"homepage":"https://github.com/martinheidegger/wcstring#readme","keywords":["unicode","visualwidth","terminal","wide character","wc","wide character string","wcs","terminal","width","wcwidth","wcswidth"],"repository":{"type":"git","url":"git+https://github.com/martinheidegger/wcstring.git"},"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"bugs":{"url":"https://github.com/martinheidegger/wcstring/issues"},"license":"ISC","readmeFilename":"Readme.md","users":{"srl":true}}