summaryrefslogtreecommitdiff
path: root/src/node_modules/stringz/README.md
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/stringz/README.md
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/stringz/README.md')
-rw-r--r--src/node_modules/stringz/README.md186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/node_modules/stringz/README.md b/src/node_modules/stringz/README.md
new file mode 100644
index 0000000..a518f52
--- /dev/null
+++ b/src/node_modules/stringz/README.md
@@ -0,0 +1,186 @@
+# Stringz [![Build Status](https://travis-ci.org/sallar/stringz.svg?branch=master)](https://travis-ci.org/sallar/stringz) [![codecov](https://codecov.io/gh/sallar/stringz/branch/master/graph/badge.svg)](https://codecov.io/gh/sallar/stringz) [![npm](https://img.shields.io/npm/dm/stringz.svg)](https://www.npmjs.com/package/stringz)
+
+A really small, performant, unicode-aware library for working
+with Strings in Node.js.
+
+Javascript has a serious problem with unicode. Even ES6 canโ€™t solve the problem
+entirely since some characters like the new colored emojis are three bytes
+instead of two bytes. Sometimes even more! `"๐Ÿ‘๐Ÿฝ".length` returns `4` which is
+totally wrong (hint: it should be 1!). ES6's `Array.from` tried to solve this,
+but that even fails: `Array.from("๐Ÿ‘๐Ÿฝ")` returns `["๐Ÿ‘", "๐Ÿฝ"]` which is
+incorrect. This library tries to tackle all these problems with a mega RegExp.
+[Read More Here](https://mathiasbynens.be/notes/javascript-unicode).
+
+## Features
+
+* Unicode-aware string manipulation tools
+* High performance
+
+## Install
+
+```bash
+$ npm install stringz --save
+```
+
+And import it in your awesome node app:
+
+```javascript
+// ES2015+
+import * as stringz from 'stringz'; // OR:
+import { limit, substring, length, substr } from 'stringz';
+```
+
+```javascript
+// CommonJS
+const stringz = require('stringz'); // OR:
+const { limit, substr } = require('stringz');
+```
+
+## Usage
+
+* [`limit()`](#limit-string-to-width)
+* [`length()`](#string-length)
+* [`substring()`](#substring)
+* [`substr()`](#substr)
+* [`indexOf()`](#indexof)
+* [`toArray()`](#toarray)
+
+### Limit String to Width
+
+ function limit(str[, limit[, padStr[, padPosition]]])
+
+| Param | Type | Default | Description |
+| ----------- | ------------------- | -------------------- | --------------------------------------------------------- |
+| str | <code>String</code> | _none_ | The string to be limited |
+| limit | <code>Number</code> | <code>16</code> | Desired string length |
+| padStr | <code>String</code> | <code>"#"</code> | Character to pad the output with |
+| padPosition | <code>String</code> | <code>"right"</code> | Pad position: <code>"right"</code> or <code>"left"</code> |
+
+#### Examples
+
+```javascript
+// Truncate:
+limit('Lifeโ€™s like a box of chocolates.', 20); // "Life's like a box of"
+
+// Pad:
+limit('Everybody loves emojis!', 26, '๐Ÿ’ฉ'); // "Everybody loves emojis!๐Ÿ’ฉ๐Ÿ’ฉ๐Ÿ’ฉ"
+limit('What are you looking at?', 30, '+', 'left'); // "++++++What are you looking at?"
+
+// Unicode Aware:
+limit('๐Ÿค”๐Ÿค”๐Ÿค”', 2); // "๐Ÿค”๐Ÿค”"
+limit('๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ', 4, '๐Ÿ‘๐Ÿฝ'); // "๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ"
+```
+
+### String Length
+
+ function length(str)
+
+| Param | Type | Default | Description |
+| ----- | ------------------- | ------- | ------------------------------- |
+| str | <code>String</code> | _none_ | String to return the length for |
+
+#### Examples
+
+```javascript
+length('Iรฑtรซrnรขtiรดnร lizรฆtiรธnโ˜ƒ๐Ÿ’ฉ'); // 22
+```
+
+### Substring
+
+ function substring(str, start[, end])
+
+| Param | Type | Default | Description |
+| ----- | ------------------- | ------------- | -------------------- |
+| str | <code>String</code> | _none_ | String to be devided |
+| start | <code>Number</code> | _none_ | Start position |
+| end | <code>Number</code> | End of string | End position |
+
+#### Examples
+
+```javascript
+substring('Emojis ๐Ÿ‘๐Ÿฝ are ๐Ÿ† poison. ๐ŸŒฎs are bad.', 7, 14); // "๐Ÿ‘๐Ÿฝ are ๐Ÿ†"
+```
+
+### Substr
+
+ function substr(str[, start[, length]])
+
+| Param | Type | Default | Description |
+| ------ | ------------------- | ------------------------------------- | -------------------- |
+| str | <code>String</code> | _none_ | String to be devided |
+| start | <code>Number</code> | Start of string | Start position |
+| length | <code>Number</code> | String length minus `start` parameter | Length of result |
+
+#### Examples
+
+```javascript
+substr('A.C. Milan ๐Ÿ‡ฎ๐Ÿ‡นโšฝ๏ธ', 5, 7); // "Milan ๐Ÿ‡ฎ๐Ÿ‡น"
+```
+
+### IndexOf
+
+ function indexOf(str[, searchStr[, position]])
+
+| Param | Type | Default | Description |
+| --------- | ------------------- | ------- | --------------------- |
+| str | <code>String</code> | _none_ | String to get index |
+| searchStr | <code>String</code> | _none_ | String to be searched |
+| position | <code>Number</code> | 0 | Start of searching |
+
+#### Examples
+
+```javascript
+indexOf('Emojis ๐Ÿ‘๐Ÿฝ are ๐Ÿ† poison. ๐ŸŒฎs are bad.', 'are'); // 9
+indexOf('Emojis ๐Ÿ‘๐Ÿฝ are ๐Ÿ† poison. ๐ŸŒฎs are bad.', 'are', 10); // 26
+```
+
+### ToArray
+
+ function toArray(str)
+
+| Param | Type | Default | Description |
+| ----- | ------------------- | ------- | -------------------------- |
+| str | <code>String</code> | _none_ | String to convert to array |
+
+#### Examples
+
+```javascript
+toArray('๐Ÿ‘๐Ÿฝ๐Ÿ†๐ŸŒฎ'); // ['๐Ÿ‘๐Ÿฝ', '๐Ÿ†', '๐ŸŒฎ']
+```
+
+## Test
+
+```bash
+$ npm test
+```
+
+## Benchmark
+
+This library scores high in a length benchmark (it's intended usage) and should
+be fast for most use case.
+
+```
+Stringz .length (accurate) x 861,039 ops/sec ยฑ1.57% (84 runs sampled)
+Lodash .toArray (accurate) x 795,108 ops/sec ยฑ2.13% (82 runs sampled)
+Emoji Aware .split (inaccurate) x 2,269 ops/sec ยฑ1.38% (85 runs sampled)
+Spliddit .length (inaccurate) x 487,718 ops/sec ยฑ2.21% (83 runs sampled)
+UTF8 Length (inaccurate) x 232,918 ops/sec ยฑ1.02% (87 runs sampled)
+Fastest is Stringz .length
+```
+
+To run benchmarks yourself:
+
+```bash
+$ cd ./benchmark
+$ npm install
+$ node run.js
+```
+
+## Changelog
+
+[Moved to CHANGELOG.md](CHANGELOG.md)
+
+## License
+
+This software is released under the
+[MIT License](http://sallar.mit-license.org/).