package/LICENSE000644 0000002125 3560116604 010265 0ustar00000000 000000 The MIT License Copyright (c) 2014 Juan Cruz Viotti, Inc. https://jviotti.github.io Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/lib/unicode-length.js000644 0000002074 3560116604 013274 0ustar00000000 000000 var punycode = require('punycode') function ansiRegex () { const pattern = [ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))' ].join('|') return new RegExp(pattern, 'g') } // From https://github.com/mathiasbynens/esrever/blob/master/scripts/export-data.js var REGEX_SYMBOLS = /([\0-\u02FF\u0370-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uDC00-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF])([\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g exports.get = function (input) { if (input == null) { throw new Error('Missing input') } if (typeof input !== 'string') { throw new Error('Invalid input: ' + input) } input = input.replace(ansiRegex(), '') const stripped = input.replace(REGEX_SYMBOLS, function ($0, symbol, combiningMarks) { return symbol }) return punycode.ucs2.decode(stripped).length } if (process.env['NODE_DEV'] === 'TEST') { exports.ansiRegex = ansiRegex } package/package.json000644 0000001445 3560116604 011552 0ustar00000000 000000 { "name": "unicode-length", "version": "2.1.0", "description": "Get the length of unicode strings", "main": "lib/unicode-length.js", "types": "index.d.ts", "files": [ "lib/unicode-length.js" ], "homepage": "https://github.com/jviotti/unicode-length", "repository": { "type": "git", "url": "git://github.com/jviotti/unicode-length.git" }, "keywords": [ "unicode", "string", "length" ], "directories": { "test": "tests" }, "scripts": { "lint": "standard", "test": "node ./tests/unicode-length.spec.js | tap-spec" }, "author": "Juan Cruz Viotti ", "license": "MIT", "devDependencies": { "standard": "^12.0.1", "tap-spec": "^5.0.0", "tape": "^4.10.2" }, "dependencies": { "punycode": "^2.0.0" } } package/README.md000644 0000002544 3560116604 010544 0ustar00000000 000000 unicode-length -------------- [![npm version](https://badge.fury.io/js/unicode-length.svg)](http://badge.fury.io/js/unicode-length) [![dependencies](https://david-dm.org/jviotti/unicode-length.png)](https://david-dm.org/jviotti/unicode-length.png) [![Build Status](https://travis-ci.org/jviotti/unicode-length.svg?branch=master)](https://travis-ci.org/jviotti/unicode-length) Installation ------------ Install `unicode-length` by running: ```sh $ npm install --save unicode-length ``` Documentation ------------- ### Number unicodeLength.get(String input) Get the length of a unicode string. Example: ```coffee unicodeLength = require('unicode-length') console.log(unicodeLength.get('汉字')) # Outputs 2 ``` Tests ----- Run the test suite by doing: ```sh $ gulp test ``` Contribute ---------- - Issue Tracker: [github.com/jviotti/unicode-length/issues](https://github.com/jviotti/unicode-length/issues) - Source Code: [github.com/jviotti/unicode-length](https://github.com/jviotti/unicode-length) Before submitting a PR, please make sure that you include tests, and that [coffeelint](http://www.coffeelint.org/) runs without any warning: ```sh $ gulp lint ``` Support ------- If you're having any problem, please [raise an issue](https://github.com/jviotti/unicode-length/issues/new) on GitHub. License ------- The project is licensed under the MIT license.