{"name":"printable-characters","version":"1.0.2","description":"A function for matching/counting [non-]printable characters in a string","main":"printable-characters.js","scripts":{"test":"mocha --reporter spec --watch"},"repository":{"type":"git","url":"git+https://github.com/xpl/printable-characters.git"},"keywords":["visible symbols","invisible symbols","printable characters","non-printable characters","nonprintable characters","characters","symbols","string length","real string length","string trimming"],"author":{"name":"Vitaly Gordon","email":"rocket.mind@gmail.com"},"license":"Unlicense","homepage":"https://github.com/xpl/printable-characters","devDependencies":{"babel-preset-es2015":"^6.14.0","mocha":"^2.4.5"},"gitHead":"99d570b781cfd00f88176ed639fa6aa3354e8610","bugs":{"url":"https://github.com/xpl/printable-characters/issues"},"_id":"printable-characters@1.0.2","_shasum":"ffb7e695cd7c3e942f9e780861330137dd9da156","_from":".","_npmVersion":"4.1.2","_nodeVersion":"8.0.0-nightly20170210b471392f8c","_npmUser":{"name":"xpl","email":"rocket.mind@gmail.com"},"dist":{"shasum":"ffb7e695cd7c3e942f9e780861330137dd9da156","tarball":"http://registry-npm.ywwl.com/printable-characters/download/printable-characters-1.0.2.tgz","integrity":"sha512-E1DhifdnVOfGq4Bulunzp45WbiH418Pj/n/Vw7WAR80gvcm+CatKZGi0sK5yY7mlyQzIcxn2mD4JqhiK4umUbw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCW8meBVp8cA0iyDvAoYQ8G6KDT8Aiui8WGZmzgBKvh0wIgUgLK6jeCt6YIUSYmBgDs8b9znyf/kq+y1smEPpBQVZo="}],"size":3856,"noattachment":false,"key":"/printable-characters/-/printable-characters-1.0.2.tgz"},"maintainers":[{"name":"xpl","email":"rocket.mind@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/printable-characters-1.0.2.tgz_1498856973395_0.15119637036696076"},"directories":{},"readme":"# printable-characters\n\n[![Build Status](https://travis-ci.org/xpl/printable-characters.svg?branch=master)](https://travis-ci.org/xpl/printable-characters) [![Coverage Status](https://coveralls.io/repos/github/xpl/printable-characters/badge.svg)](https://coveralls.io/github/xpl/printable-characters) [![npm](https://img.shields.io/npm/v/printable-characters.svg)](https://npmjs.com/package/printable-characters) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/xpl/printable-characters.svg)](https://scrutinizer-ci.com/g/xpl/printable-characters/?branch=master) [![dependencies Status](https://david-dm.org/xpl/printable-characters/status.svg)](https://david-dm.org/xpl/printable-characters)\n\nA little helper for handling strings containing zero width characters, ANSI styling, whitespaces, newlines, [weird Unicode 💩 symbols](http://blog.jonnew.com/posts/poo-dot-length-equals-two), etc.\n\n## Determining the real (visible) length of a string\n\n```javascript\nconst { strlen } = require ('printable-characters')\n\nstrlen ('foo bar') // === 7\nstrlen ('\\u001b[106mfoo bar\\u001b[49m') // === 7\n```\n\n## Detecting blank text\n\n```javascript\nconst { isBlank } = require ('printable-characters')\n\nisBlank ('foobar') // === false\nisBlank ('\\u001b[106m  \\t  \\t   \\n     \\u001b[49m') // === true\n```\n\n## Obtaining a blank string of the same width\n\n```javascript\nconst { blank } = require ('printable-characters')\n\nblank ('💩')          // === ' '\nblank ('foo')         // === '   '\nblank ('\\tfoo \\nfoo') // === '\\t    \\n   '\nblank ('\\u001b[22m\\u001b[1mfoo \\t\\u001b[39m\\u001b[22m')) // === '    \\t'\n```\n\n## Matching invisible characters\n\n```javascript\nconst { ansiEscapeCodes, zeroWidthCharacters } = require ('printable-characters')\n\nconst s = '\\u001b[106m' + 'foo' + '\\n' + 'bar' + '\\u001b[49m'\n\ns.replace (ansiEscapeCodes, '')     // === 'foo\\nbar'\n .replace (zeroWidthCharacters, '') // === 'foobar'\n```\n\n## Getting the first N visible symbols, preserving the invisible parts\n\nUse for safely truncating strings to maximum width without breaking ANSI codes:\n\n```javascript\nconst { first } = require ('printable-characters')\n\nconst s = '\\u001b[22mfoobar\\u001b[22m'\n\nfirst (s, 0) // === '\\u001b[22m\\u001b[22m'\nfirst (s, 1) // === '\\u001b[22mf\\u001b[22m'\nfirst (s, 3) // === '\\u001b[22mfoo\\u001b[22m'\nfirst (s, 6) // === '\\u001b[22mfoobar\\u001b[22m'\n```\n\n## Extracting the invisible parts followed by the visible ones (parsing)\n\n```javascript\nconst { partition } = require ('printable-characters')\n\npartition ('')                        // [                                                     ])\npartition ('foo')                     // [['',          'foo']                                 ])\npartition ('\\u001b[1mfoo')            // [['\\u001b[1m', 'foo']                                 ])\npartition ('\\u001b[1mfoo\\u0000bar')   // [['\\u001b[1m', 'foo'],   ['\\u0000', 'bar']            ])\npartition ('\\u001b[1mfoo\\u0000bar\\n') // [['\\u001b[1m', 'foo'],   ['\\u0000', 'bar'], ['\\n', '']])\n```\n\n## Applications\n\n- [as-table](https://github.com/xpl/as-table) — a simple function that prints objects as ASCII tables\n- [string.bullet](https://github.com/xpl/string.bullet) — ASCII-mode bulleting for the list-style data\n- [string.ify](https://github.com/xpl/string.ify) — a fancy pretty printer for the JavaScript entities\n- [Ololog!](https://github.com/xpl/ololog) — a better `console.log` for the log-driven debugging junkies!\n\n## TODO\n\nHandle multi-component emojis, as in [this article](http://blog.jonnew.com/posts/poo-dot-length-equals-two):\n\n```javascript\nassert.equal (strlen ('👩‍❤️‍💋‍👩'), 1)  // FAILING, see http://blog.jonnew.com/posts/poo-dot-length-equals-two for possible solution\nassert.equal (blank ('👩‍❤️‍💋‍👩'), ' ') // FAILING, see http://blog.jonnew.com/posts/poo-dot-length-equals-two for possible solution\n```\n","publish_time":1498856974312,"_cnpm_publish_time":1498856974312,"dist-tags":{"latest":"1.0.42"}}