summaryrefslogtreecommitdiff
path: root/src/node_modules/stringz
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_modules/stringz')
-rw-r--r--src/node_modules/stringz/CHANGELOG.md19
-rw-r--r--src/node_modules/stringz/LICENSE21
-rw-r--r--src/node_modules/stringz/README.md186
-rw-r--r--src/node_modules/stringz/dist/index.d.ts57
-rw-r--r--src/node_modules/stringz/dist/index.d.ts.map1
-rw-r--r--src/node_modules/stringz/dist/index.js199
-rw-r--r--src/node_modules/stringz/package.json66
7 files changed, 549 insertions, 0 deletions
diff --git a/src/node_modules/stringz/CHANGELOG.md b/src/node_modules/stringz/CHANGELOG.md
new file mode 100644
index 0000000..9d21a24
--- /dev/null
+++ b/src/node_modules/stringz/CHANGELOG.md
@@ -0,0 +1,19 @@
+# Changelog
+
+| Version | Date | Notes |
+| ------- | ---------- | ------------------------------------------------------------------- |
+| 2.1.0 | 2020-02-21 | Use new RegEx library to fix some counting issues |
+| 2.0.0 | 2019-05-26 | Refactor to Typescript and remove Node 4 & 5 support - BREAKING |
+| 1.0.0 | 2018-04-02 | Move the astral regex to it's own package |
+| 0.4.0 | 2017-12-08 | [New `toArray` function](https://github.com/sallar/stringz/pull/24) |
+| 0.3.0 | 2017-11-29 | [New `indexOf` function](https://github.com/sallar/stringz/pull/22) |
+| 0.2.3 | 2017-09-19 | Add `.babelrc` to `.gitignore` |
+| 0.2.2 | 2017-06-20 | Fix Typescript Definition Issue #14 |
+| 0.2.1 | 2017-05-27 | Add Typescript Definitions |
+| 0.2.0 | 2017-04-30 | [New `substr` function](https://github.com/sallar/stringz/pull/10) |
+| 0.1.2 | 2017-04-25 | Fix null length issue #8 |
+| 0.1.1 | 2016-07-31 | More strict type checking, more tests |
+| 0.1.0 | 2016-07-29 | Renamed to Stringz, more tools |
+| 0.0.10 | 2016-07-29 | Fixed substring issue |
+| 0.0.9 | 2016-07-28 | Fixed unicode string length issue |
+| 0.0.8 | 2016-07-26 | First usable release |
diff --git a/src/node_modules/stringz/LICENSE b/src/node_modules/stringz/LICENSE
new file mode 100644
index 0000000..fb6f56c
--- /dev/null
+++ b/src/node_modules/stringz/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Sallar Kaboli
+
+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.
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/).
diff --git a/src/node_modules/stringz/dist/index.d.ts b/src/node_modules/stringz/dist/index.d.ts
new file mode 100644
index 0000000..9366011
--- /dev/null
+++ b/src/node_modules/stringz/dist/index.d.ts
@@ -0,0 +1,57 @@
+/**
+ * Converts a string to an array of string chars
+ * @param {string} str The string to turn into array
+ * @returns {string[]}
+ */
+export declare function toArray(str: string): string[];
+/**
+ * Returns the length of a string
+ *
+ * @export
+ * @param {string} str
+ * @returns {number}
+ */
+export declare function length(str: string): number;
+/**
+ * Returns a substring by providing start and end position
+ *
+ * @export
+ * @param {string} str
+ * @param {number} [begin=0] Starting position
+ * @param {number} end End position
+ * @returns {string}
+ */
+export declare function substring(str: string, begin?: number, end?: number): string;
+/**
+ * Returns a substring by providing start position and length
+ *
+ * @export
+ * @param {string} str
+ * @param {number} [begin=0] Starting position
+ * @param {number} len Desired length
+ * @returns {string}
+ */
+export declare function substr(str: string, begin?: number, len?: number): string;
+/**
+ * Enforces a string to be a certain length by
+ * adding or removing characters
+ *
+ * @export
+ * @param {string} str
+ * @param {number} [limit=16] Limit
+ * @param {string} [padString='#'] The Pad String
+ * @param {string} [padPosition='right'] The Pad Position
+ * @returns {string}
+ */
+export declare function limit(str: string, limit?: number, padString?: string, padPosition?: string): string;
+/**
+ * Returns the index of the first occurrence of a given string
+ *
+ * @export
+ * @param {string} str
+ * @param {string} [searchStr] the string to search
+ * @param {number} [pos] starting position
+ * @returns {number}
+ */
+export declare function indexOf(str: string, searchStr: string, pos?: number): number;
+//# sourceMappingURL=index.d.ts.map \ No newline at end of file
diff --git a/src/node_modules/stringz/dist/index.d.ts.map b/src/node_modules/stringz/dist/index.d.ts.map
new file mode 100644
index 0000000..3307d5b
--- /dev/null
+++ b/src/node_modules/stringz/dist/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAK7C;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,MAAU,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAmBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAwC3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CACnB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,MAAW,EAClB,SAAS,GAAE,MAAY,EACvB,WAAW,GAAE,MAAgB,GAC5B,MAAM,CA2BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,GAAG,GAAE,MAAU,GACd,MAAM,CAgDR"} \ No newline at end of file
diff --git a/src/node_modules/stringz/dist/index.js b/src/node_modules/stringz/dist/index.js
new file mode 100644
index 0000000..e53e862
--- /dev/null
+++ b/src/node_modules/stringz/dist/index.js
@@ -0,0 +1,199 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+// @ts-ignore
+var char_regex_1 = __importDefault(require("char-regex"));
+/**
+ * Converts a string to an array of string chars
+ * @param {string} str The string to turn into array
+ * @returns {string[]}
+ */
+function toArray(str) {
+ if (typeof str !== 'string') {
+ throw new Error('A string is expected as input');
+ }
+ return str.match(char_regex_1.default()) || [];
+}
+exports.toArray = toArray;
+/**
+ * Returns the length of a string
+ *
+ * @export
+ * @param {string} str
+ * @returns {number}
+ */
+function length(str) {
+ // Check for input
+ if (typeof str !== 'string') {
+ throw new Error('Input must be a string');
+ }
+ var match = str.match(char_regex_1.default());
+ return match === null ? 0 : match.length;
+}
+exports.length = length;
+/**
+ * Returns a substring by providing start and end position
+ *
+ * @export
+ * @param {string} str
+ * @param {number} [begin=0] Starting position
+ * @param {number} end End position
+ * @returns {string}
+ */
+function substring(str, begin, end) {
+ if (begin === void 0) { begin = 0; }
+ // Check for input
+ if (typeof str !== 'string') {
+ throw new Error('Input must be a string');
+ }
+ // Even though negative numbers work here, theyre not in the spec
+ if (typeof begin !== 'number' || begin < 0) {
+ begin = 0;
+ }
+ if (typeof end === 'number' && end < 0) {
+ end = 0;
+ }
+ var match = str.match(char_regex_1.default());
+ if (!match)
+ return '';
+ return match.slice(begin, end).join('');
+}
+exports.substring = substring;
+/**
+ * Returns a substring by providing start position and length
+ *
+ * @export
+ * @param {string} str
+ * @param {number} [begin=0] Starting position
+ * @param {number} len Desired length
+ * @returns {string}
+ */
+function substr(str, begin, len) {
+ if (begin === void 0) { begin = 0; }
+ // Check for input
+ if (typeof str !== 'string') {
+ throw new Error('Input must be a string');
+ }
+ var strLength = length(str);
+ // Fix type
+ if (typeof begin !== 'number') {
+ begin = parseInt(begin, 10);
+ }
+ // Return zero-length string if got oversize number.
+ if (begin >= strLength) {
+ return '';
+ }
+ // Calculating postive version of negative value.
+ if (begin < 0) {
+ begin += strLength;
+ }
+ var end;
+ if (typeof len === 'undefined') {
+ end = strLength;
+ }
+ else {
+ // Fix type
+ if (typeof len !== 'number') {
+ len = parseInt(len, 10);
+ }
+ end = len >= 0 ? len + begin : begin;
+ }
+ var match = str.match(char_regex_1.default());
+ if (!match)
+ return '';
+ return match.slice(begin, end).join('');
+}
+exports.substr = substr;
+/**
+ * Enforces a string to be a certain length by
+ * adding or removing characters
+ *
+ * @export
+ * @param {string} str
+ * @param {number} [limit=16] Limit
+ * @param {string} [padString='#'] The Pad String
+ * @param {string} [padPosition='right'] The Pad Position
+ * @returns {string}
+ */
+function limit(str, limit, padString, padPosition) {
+ if (limit === void 0) { limit = 16; }
+ if (padString === void 0) { padString = '#'; }
+ if (padPosition === void 0) { padPosition = 'right'; }
+ // Input should be a string, limit should be a number
+ if (typeof str !== 'string' || typeof limit !== 'number') {
+ throw new Error('Invalid arguments specified');
+ }
+ // Pad position should be either left or right
+ if (['left', 'right'].indexOf(padPosition) === -1) {
+ throw new Error('Pad position should be either left or right');
+ }
+ // Pad string can be anything, we convert it to string
+ if (typeof padString !== 'string') {
+ padString = String(padString);
+ }
+ // Calculate string length considering astral code points
+ var strLength = length(str);
+ if (strLength > limit) {
+ return substring(str, 0, limit);
+ }
+ else if (strLength < limit) {
+ var padRepeats = padString.repeat(limit - strLength);
+ return padPosition === 'left' ? padRepeats + str : str + padRepeats;
+ }
+ return str;
+}
+exports.limit = limit;
+/**
+ * Returns the index of the first occurrence of a given string
+ *
+ * @export
+ * @param {string} str
+ * @param {string} [searchStr] the string to search
+ * @param {number} [pos] starting position
+ * @returns {number}
+ */
+function indexOf(str, searchStr, pos) {
+ if (pos === void 0) { pos = 0; }
+ if (typeof str !== 'string') {
+ throw new Error('Input must be a string');
+ }
+ if (str === '') {
+ if (searchStr === '') {
+ return 0;
+ }
+ return -1;
+ }
+ // fix type
+ pos = Number(pos);
+ pos = isNaN(pos) ? 0 : pos;
+ searchStr = String(searchStr);
+ var strArr = toArray(str);
+ if (pos >= strArr.length) {
+ if (searchStr === '') {
+ return strArr.length;
+ }
+ return -1;
+ }
+ if (searchStr === '') {
+ return pos;
+ }
+ var searchArr = toArray(searchStr);
+ var finded = false;
+ var index;
+ for (index = pos; index < strArr.length; index += 1) {
+ var searchIndex = 0;
+ while (searchIndex < searchArr.length &&
+ searchArr[searchIndex] === strArr[index + searchIndex]) {
+ searchIndex += 1;
+ }
+ if (searchIndex === searchArr.length &&
+ searchArr[searchIndex - 1] === strArr[index + searchIndex - 1]) {
+ finded = true;
+ break;
+ }
+ }
+ return finded ? index : -1;
+}
+exports.indexOf = indexOf;
diff --git a/src/node_modules/stringz/package.json b/src/node_modules/stringz/package.json
new file mode 100644
index 0000000..9644b4e
--- /dev/null
+++ b/src/node_modules/stringz/package.json
@@ -0,0 +1,66 @@
+{
+ "name": "stringz",
+ "version": "2.1.0",
+ "description": "Zero-dependency unicode-aware string tools",
+ "main": "dist/index.js",
+ "files": [
+ "dist/index.js",
+ "dist/index.d.ts",
+ "dist/index.d.ts.map"
+ ],
+ "types": "dist/index.d.ts",
+ "scripts": {
+ "test": "jest --coverage",
+ "format": "prettier --write '{src,test,benchmark}/**/*.{js,ts}'",
+ "lint": "prettier-check '{src,test,benchmark}/**/*.{js,ts}'",
+ "nyc-report": "codecov",
+ "precommit": "lint-staged",
+ "prepublish": "npm run build",
+ "build": "tsc"
+ },
+ "lint-staged": {
+ "{src,test,benchmark}/**/*.{js,ts}": [
+ "prettier --write",
+ "git add"
+ ]
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/sallar/stringz.git"
+ },
+ "keywords": [
+ "string",
+ "truncate",
+ "length",
+ "unicode",
+ "substr",
+ "substring",
+ "emoji",
+ "pad",
+ "leftpad",
+ "rightpad",
+ "length",
+ "count"
+ ],
+ "author": "Sallar Kaboli <sallar.kaboli@gmail.com>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/sallar/stringz/issues"
+ },
+ "homepage": "https://github.com/sallar/stringz#readme",
+ "devDependencies": {
+ "@types/assert": "^1.4.2",
+ "@types/jest": "^24.0.13",
+ "codecov": "^3.5.0",
+ "husky": "^2.3.0",
+ "jest": "^24.8.0",
+ "lint-staged": "^8.1.7",
+ "prettier": "^1.9.1",
+ "prettier-check": "^2.0.0",
+ "ts-jest": "^24.0.2",
+ "typescript": "^3.4.5"
+ },
+ "dependencies": {
+ "char-regex": "^1.0.2"
+ }
+}