'
27 | * @returns { String } The decoded data.
28 | */
29 | export default (value: string): string =>
30 | replace(value, '(&\\w+;)', (match: string, index: number): string => {
31 | if (typeof entitiesDecode[index] !== 'undefined') {
32 | return entitiesDecode[index]
33 | }
34 | return match
35 | })
36 |
--------------------------------------------------------------------------------
/src/htmlencode.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import entitiesEncode from './lib/entitiesencode'
3 | import replace from './replace'
4 | /**
5 | * @module htmlEncode
6 | * @description
7 | * Convert all applicable characters to HTML entities.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the htmlEncode function
14 | * ```sh
15 | * yarn add strman.htmlencode
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { htmlEncode } from 'strman'
20 | * // OR
21 | * import htmlEncode from 'strman.htmlencode'
22 | * ```
23 | * @param {String} value value to encode.
24 | * @example
25 | * htmlEncode('
')
26 | * // => '<div>'
27 | * @returns { String } The encoded data.
28 | */
29 | export default (value: string): string =>
30 | replace(
31 | value,
32 | '[\\u00A0-\\u9999<>\\&]',
33 | (match: string): string => {
34 | if (typeof entitiesEncode[match] !== 'undefined') {
35 | return entitiesEncode[match]
36 | }
37 | return match
38 | },
39 | true,
40 | true,
41 | )
42 |
--------------------------------------------------------------------------------
/src/indexof.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toCaseSensitive from './lib/case'
3 | /**
4 | * @module inequal
5 | * @description
6 | * The indexOf() method returns the index within the calling String of the first occurrence
7 | * of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the inequal function
14 | * ```sh
15 | * yarn add strman.inequal
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { inequal } from 'strman'
20 | * // OR
21 | * import inequal from 'strman.inequal'
22 | * ```
23 | * @param {String} value The String!
24 | * @param {String} needle Value to search.
25 | * @param {Number} [offset = 0] Offset to search.
26 | * @param {Boolean} [caseSensitive = true] if you use caseSensitive to test.
27 | * @example
28 | * indexOf('strman', 'man')
29 | * // => 3
30 | * @returns {Number} Return position of the first occurrence of 'needle'.
31 | */
32 | export default (
33 | value: string,
34 | needle: string,
35 | offset: number = 0,
36 | caseSensitive: boolean = true,
37 | ): number =>
38 | toCaseSensitive(value, caseSensitive).indexOf(toCaseSensitive(needle, caseSensitive), offset)
39 |
--------------------------------------------------------------------------------
/src/inequal.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module inequal
4 | * @description
5 | * Tests if two strings are inequal.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the inequal function
12 | * ```sh
13 | * yarn add strman.inequal
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { inequal } from 'strman'
18 | * // OR
19 | * import inequal from 'strman.inequal'
20 | * ```
21 | * @param {String} stringA - String for the comparative
22 | * @param {String} stringB - String to be compared
23 | * @example
24 | * inequal('foo', 'foo')
25 | * // => false
26 | * @returns {Boolean} [stringA] is inequal [stringB]
27 | */
28 | export default (stringA: string, stringB: string): boolean => stringA !== stringB
29 |
--------------------------------------------------------------------------------
/src/insert.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import _substr from './substr'
3 | import append from './append'
4 | /**
5 | * @module insert
6 | * @description
7 | * Inserts 'substr' into the 'value' at the 'index' provided.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the insert function
14 | * ```sh
15 | * yarn add strman.insert
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { insert } from 'strman'
20 | * // OR
21 | * import insert from 'strman.insert'
22 | * ```
23 | * @param {String} value The String!
24 | * @param {String} substr Value to insert.
25 | * @param {Number} index Index to insert substr.
26 | * @example
27 | * const title = "trman"
28 | * insert(title, 's', 0)
29 | * // => 'strman'
30 | * @returns {String} String with substr added.
31 | */
32 | export default (value: string, substr: string, index: number): string => {
33 | if (index > value.length) {
34 | return value
35 | }
36 |
37 | const start = _substr(value, 0, index)
38 | const end = _substr(value, index, value.length)
39 |
40 | return append(start, substr, end)
41 | }
42 |
--------------------------------------------------------------------------------
/src/islowercase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toLowerCase from './tolowercase'
3 | /**
4 | * @module isLowerCase
5 | * @description
6 | * Verify if has lowerCase
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the isLowerCase function
13 | * ```sh
14 | * yarn add strman.islowercase
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { isLowerCase } from 'strman'
19 | * // OR
20 | * import isLowerCase from 'strman.islowercase'
21 | * ```
22 | * @param {String} value - The String!
23 | * @playground
24 | * const title = 'A Javascript string manipulation library.'
25 | * isLowerCase(title)
26 | * // => false
27 | * @returns {Boolean} String is lowercase?
28 | */
29 | export default (value: string): boolean => value === toLowerCase(value)
30 |
--------------------------------------------------------------------------------
/src/isstring.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module isString
4 | * @description
5 | * Checks whether a string.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the isString function
12 | * ```sh
13 | * yarn add strman.isstring
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { isString } from 'strman'
18 | * // OR
19 | * import isString from 'strman.isstring'
20 | * ```
21 | * @param {String} value The String!
22 | * @example
23 | * const title = 'A Javascript string manipulation library.'
24 | * isString(title)
25 | * // => true
26 | * @returns {Boolean} if 'value' isString, return true, else false.
27 | */
28 | export default (value: string): boolean =>
29 | Object.prototype.toString.call(value) === '[object String]'
30 |
--------------------------------------------------------------------------------
/src/isuppercase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toUpperCase from './touppercase'
3 | /**
4 | * @module isUpperCase
5 | * @description
6 | * Verify if has UPPERCASE
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the isUpperCase function
13 | * ```sh
14 | * yarn add strman.isuppercase
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { isUpperCase } from 'strman'
19 | * // OR
20 | * import isUpperCase from 'strman.isuppercase'
21 | * ```
22 | * @param {String} value The String!
23 | * @example
24 | * const title = 'A Javascript string manipulation library.'
25 | * isUpperCase(title)
26 | * // => false
27 | * @returns {Boolean} String is UPPERCASE?.
28 | */
29 | export default (value: string): boolean => value === toUpperCase(value)
30 |
--------------------------------------------------------------------------------
/src/last.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import substr from './substr'
3 | /**
4 | * @module last
5 | * @description
6 | * Return the last 'n' chars of string.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the last function
13 | * ```sh
14 | * yarn add strman.last
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { last } from 'strman'
19 | * // OR
20 | * import last from 'strman.last'
21 | * ```
22 | * @param {String} value The String!
23 | * @param {Number} n Number of chars to return.
24 | * @example
25 | * const title = 'strman'
26 | * last(title, 3)
27 | * // => 'man'
28 | * @returns {String} Return 'n' lasts chars.
29 | */
30 | export default (value: string, n: number): string => substr(value, -1 * n, n)
31 |
--------------------------------------------------------------------------------
/src/lastindexof.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toCaseSensitive from './lib/case'
3 | /**
4 | * @module lastIndefOf
5 | * @description
6 | * The lastIndexOf() method returns the index within the calling String object of the last
7 | * occurrence of the specified value, searching backwards from fromIndex. Returns -1 if the
8 | * value is not found.
9 | * ## Install
10 | * Install all functions of strman
11 | * ```sh
12 | * yarn add strman
13 | * ```
14 | * or just the lastIndefOf function
15 | * ```sh
16 | * yarn add strman.lastindexof
17 | * ```
18 | * ## Usage
19 | * ```javascript
20 | * import { lastIndefOf } from 'strman'
21 | * // OR
22 | * import lastIndefOf from 'strman.lastindexof'
23 | * ```
24 | * @param {String} value The String!
25 | * @param {String} needle Value to search.
26 | * @param {Number} [offset = undefined] Offset to search.
27 | * @param {Boolean} [caseSensitive = true] if you use caseSensitive to test.
28 | * @example
29 | * const title = 'strman strman'
30 | * result = lastIndexOf(title, 'str')
31 | * // => 7
32 | * @returns {Number} Return position of the last occurrence of 'needle'.
33 | */
34 | export default (
35 | value: string,
36 | needle: string,
37 | offset: ?number = undefined,
38 | caseSensitive: boolean = true,
39 | ): number =>
40 | toCaseSensitive(value, caseSensitive).lastIndexOf(toCaseSensitive(needle, caseSensitive), offset)
41 |
--------------------------------------------------------------------------------
/src/leftpad.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import substr from './substr'
3 | import append from './append'
4 | import repeat from './repeat'
5 | /**
6 | * @module leftPad
7 | * @description
8 | * Returns a new string of a given length such that the beginning of the string is padded.
9 | * ## Install
10 | * Install all functions of strman
11 | * ```sh
12 | * yarn add strman
13 | * ```
14 | * or just the leftPad function
15 | * ```sh
16 | * yarn add strman.leftpad
17 | * ```
18 | * ## Usage
19 | * ```javascript
20 | * import { leftPad } from 'strman'
21 | * // OR
22 | * import leftPad from 'strman.leftpad'
23 | * ```
24 | * @param {String} value - The String!
25 | * @param {Number} length - Max length of String.
26 | * @param {Char} [char = ' '] - Char to repeat.
27 | * @example
28 | * const title = 'strman'
29 | * leftPad(title, 10, 0)
30 | * // => '0000strman'
31 | * @returns {String} String pad.
32 | */
33 | export default (value: string, length: number, char: string = ' '): string => {
34 | let result = value
35 | let newchar = String(char)
36 |
37 | if (newchar.length > 1) {
38 | newchar = substr(newchar, 0, 1)
39 | }
40 |
41 | const newlength = length - value.length
42 | result = append(repeat(newchar, newlength), result)
43 |
44 | return result
45 | }
46 |
--------------------------------------------------------------------------------
/src/lefttrim.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import replace from './replace'
3 | /**
4 | * @module leftTrim
5 | * @description
6 | * Remove all spaces on left.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the leftTrim function
13 | * ```sh
14 | * yarn add strman.lefttrim
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { leftTrim } from 'strman'
19 | * // OR
20 | * import leftTrim from 'strman.lefttrim'
21 | * ```
22 | * @param {String} value The String!
23 | * @param {String} [char = ''] if you need remove other char on left boarders.
24 | * @example
25 | * const title = ' strman'
26 | * leftTrim(title)
27 | * // => 'strman'
28 | * @returns {String} String without left boarders spaces.
29 | */
30 | export default (value: string, char: string = ' '): string => replace(value, `^${char}+`, '')
31 |
--------------------------------------------------------------------------------
/src/lib/ascii.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Credits for: @danielstjules
3 | * https://github.com/danielstjules/Stringy/blob/master/src/Stringy.php#L1601-L1756
4 | */
5 | export default {
6 | 0: ['°', '₀', '۰'],
7 | 1: ['¹', '₁', '۱'],
8 | 2: ['²', '₂', '۲'],
9 | 3: ['³', '₃', '۳'],
10 | 4: ['⁴', '₄', '۴', '٤'],
11 | 5: ['⁵', '₅', '۵', '٥'],
12 | 6: ['⁶', '₆', '۶', '٦'],
13 | 7: ['⁷', '₇', '۷'],
14 | 8: ['⁸', '₈', '۸'],
15 | 9: ['⁹', '₉', '۹'],
16 | a: ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ',
17 | 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ',
18 | 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ',
19 | 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'],
20 | b: ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'],
21 | c: ['ç', 'ć', 'č', 'ĉ', 'ċ'],
22 | d: ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'],
23 | e: ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė',
24 | 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ',
25 | 'ဲ', 'ე', 'ए', 'إ', 'ئ'],
26 | f: ['ф', 'φ', 'ف', 'ƒ', 'ფ'],
27 | g: ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'],
28 | h: ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'],
29 | i: ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ',
30 | 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и',
31 | 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ', 'ی'],
32 | j: ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'],
33 | k: ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'],
34 | l: ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'],
35 | m: ['м', 'μ', 'م', 'မ', 'მ'],
36 | n: ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'],
37 | o: ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ',
38 | 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို',
39 | 'ǒ', 'ǿ', 'º', 'ო', 'ओ'],
40 | p: ['п', 'π', 'ပ', 'პ', 'پ'],
41 | q: ['ყ'],
42 | r: ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'],
43 | s: ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'],
44 | t: ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'],
45 | u: ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų',
46 | 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'],
47 | v: ['в', 'ვ', 'ϐ'],
48 | w: ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'],
49 | x: ['χ', 'ξ'],
50 | y: ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'],
51 | z: ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'],
52 | aa: ['ع', 'आ', 'آ'],
53 | ae: ['ä', 'æ', 'ǽ'],
54 | ai: ['ऐ'],
55 | at: ['@'],
56 | ch: ['ч', 'ჩ', 'ჭ', 'چ'],
57 | dj: ['ђ', 'đ'],
58 | dz: ['џ', 'ძ'],
59 | ei: ['ऍ'],
60 | gh: ['غ', 'ღ'],
61 | ii: ['ई'],
62 | ij: ['ij'],
63 | kh: ['х', 'خ', 'ხ'],
64 | lj: ['љ'],
65 | nj: ['њ'],
66 | oe: ['ö', 'œ', 'ؤ'],
67 | oi: ['ऑ'],
68 | oii: ['ऒ'],
69 | ps: ['ψ'],
70 | sh: ['ш', 'შ', 'ش'],
71 | shch: ['щ'],
72 | ss: ['ß'],
73 | sx: ['ŝ'],
74 | th: ['þ', 'ϑ', 'ث', 'ذ', 'ظ'],
75 | ts: ['ц', 'ც', 'წ'],
76 | ue: ['ü'],
77 | uu: ['ऊ'],
78 | ya: ['я'],
79 | yu: ['ю'],
80 | zh: ['ж', 'ჟ', 'ژ'],
81 | '(c)': ['©'],
82 | A: ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å',
83 | 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ',
84 | 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'],
85 | B: ['Б', 'Β', 'ब'],
86 | C: ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'],
87 | D: ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'],
88 | E: ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε',
89 | 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə'],
90 | F: ['Ф', 'Φ'],
91 | G: ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'],
92 | H: ['Η', 'Ή', 'Ħ'],
93 | I: ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ',
94 | 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'],
95 | K: ['К', 'Κ'],
96 | L: ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'],
97 | M: ['М', 'Μ'],
98 | N: ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'],
99 | O: ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø',
100 | 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'],
101 | P: ['П', 'Π'],
102 | R: ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'],
103 | S: ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'],
104 | T: ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'],
105 | U: ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У',
106 | 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ'],
107 | V: ['В'],
108 | W: ['Ω', 'Ώ', 'Ŵ'],
109 | X: ['Χ', 'Ξ'],
110 | Y: ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'],
111 | Z: ['Ź', 'Ž', 'Ż', 'З', 'Ζ'],
112 | AE: ['Ä', 'Æ', 'Ǽ'],
113 | CH: ['Ч'],
114 | DJ: ['Ђ'],
115 | DZ: ['Џ'],
116 | GX: ['Ĝ'],
117 | HX: ['Ĥ'],
118 | IJ: ['IJ'],
119 | JX: ['Ĵ'],
120 | KH: ['Х'],
121 | LJ: ['Љ'],
122 | NJ: ['Њ'],
123 | OE: ['Ö', 'Œ'],
124 | PS: ['Ψ'],
125 | SH: ['Ш'],
126 | SHCH: ['Щ'],
127 | SS: ['ẞ'],
128 | TH: ['Þ'],
129 | TS: ['Ц'],
130 | UE: ['Ü'],
131 | YA: ['Я'],
132 | YU: ['Ю'],
133 | ZH: ['Ж'],
134 | ' ': ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", // eslint-disable-line
135 | "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", // eslint-disable-line
136 | "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"] // eslint-disable-line
137 | }
138 |
--------------------------------------------------------------------------------
/src/lib/case.js:
--------------------------------------------------------------------------------
1 | import toUpperCase from '../touppercase'
2 |
3 | export default (value, caseSensitive = true) => {
4 | if (caseSensitive) {
5 | return value
6 | }
7 | return toUpperCase(value)
8 | }
9 |
--------------------------------------------------------------------------------
/src/lib/decode.js:
--------------------------------------------------------------------------------
1 | export default (value, length, base) =>
2 | value.match(new RegExp(`.{1,${length}}`, 'g'))
3 | .map(string => String.fromCharCode(parseInt(string, base))).join('')
4 |
--------------------------------------------------------------------------------
/src/lib/encode.js:
--------------------------------------------------------------------------------
1 | import chars from '../chars'
2 | import leftPad from '../leftpad'
3 |
4 | export default (value, length, base) =>
5 | chars(value).map(data => leftPad(data.charCodeAt(0).toString(base), length, '0')).join('')
6 |
--------------------------------------------------------------------------------
/src/lib/numericalbase.js:
--------------------------------------------------------------------------------
1 | export const BASE_HEXADECIMAL = 16
2 | export const LENGTH_HEXADECIMAL = 4
3 |
4 | export const BASE_BINARY = 2
5 | export const LENGTH_BINARY = 16
6 |
7 | export const BASE_DECIMAL = 10
8 | export const LENGTH_DECIMAL = 5
9 |
--------------------------------------------------------------------------------
/src/lib/poparray.js:
--------------------------------------------------------------------------------
1 | export default array => array.slice(0, -1)
2 |
--------------------------------------------------------------------------------
/src/prepend.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import prependArray from './prependarray'
3 | /**
4 | * @module prepend
5 | * @description
6 | * Returns a new string starting with 'prepends'.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the prepend function
13 | * ```sh
14 | * yarn add strman.prepend
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { prepend } from 'strman'
19 | * // OR
20 | * import prepend from 'strman.prepend'
21 | * ```
22 | * @param {String} value - The String!
23 | * @param {...String} prepends - Strings to prepend.
24 | * @example
25 | * const title = 'strman'
26 | * prepend(title, '_')
27 | * // => '_strman'
28 | * @returns {String} The String prepended!
29 | */
30 | export default (value: string, ...prepends: Array
): string => prependArray(value, prepends)
31 |
--------------------------------------------------------------------------------
/src/prependarray.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module prependArray
4 | * @description
5 | * Returns a new string starting with 'prepends'.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the prependArray function
12 | * ```sh
13 | * yarn add strman.prependarray
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { prependArray } from 'strman'
18 | * // OR
19 | * import prependArray from 'strman.prependarray'
20 | * ```
21 | * @param {String} value The String!
22 | * @param {String[]} prepends Strings to prepend.
23 | * @example
24 | * const title = 'strman'
25 | * prependArray(title, ['_'])
26 | * // => '_strman'
27 | * @returns {String} The String prepended!
28 | */
29 | export default (value: string, prepends: Array = []): string => {
30 | if (prepends.length === 0) {
31 | return value
32 | }
33 | return prepends.join('') + value
34 | }
35 |
--------------------------------------------------------------------------------
/src/removeemptystrings.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module removeEmptyStrings
4 | * @description
5 | * Remove empty strings from strings array.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the removeEmptyStrings function
12 | * ```sh
13 | * yarn add strman.removeemptystrings
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { removeEmptyStrings } from 'strman'
18 | * // OR
19 | * import removeEmptyStrings from 'strman.removeemptystrings'
20 | * ```
21 | * @param {String[]} strings - Array of strings that will be cleaned.
22 | * @example
23 | * const titles = ['A Javascript string manipulation library.', null, undefined, '', ' ']
24 | * removeEmptyStrings(titles)
25 | * // => ['A Javascript string manipulation library.']
26 | * @returns {String[]} Array of strings without empty strings.
27 | */
28 | export default (strings: Array): Array =>
29 | strings.filter(string => string && string !== '')
30 |
--------------------------------------------------------------------------------
/src/removeleft.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import startsWith from './startswith'
3 | import substr from './substr'
4 | /**
5 | * @module removeLeft
6 | * @description
7 | * Returns a new string with the 'prefix' removed, if present.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the removeLeft function
14 | * ```sh
15 | * yarn add strman.removeleft
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { removeLeft } from 'strman'
20 | * // OR
21 | * import removeLeft from 'strman.removeleft'
22 | * ```
23 | * @param {String} value The String!
24 | * @param {String} prefix String to remove on left.
25 | * @param {Boolean} [caseSensitive = true] If you need to caseSensitive.
26 | * @example
27 | * const title = 'strman'
28 | * removeLeft(title, 'str')
29 | * // => 'man'
30 | * @returns {String} The String without prefix!
31 | */
32 | export default (value: string, prefix: string, caseSensitive: boolean = true): string => {
33 | if (startsWith(value, prefix, 0, caseSensitive)) {
34 | return substr(value, prefix.length)
35 | }
36 | return value
37 | }
38 |
--------------------------------------------------------------------------------
/src/removenonwords.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import replace from './replace'
3 | /**
4 | * @module removeNonWords
5 | * @description
6 | * Remove all non word characters.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the removeNonWords function
13 | * ```sh
14 | * yarn add strman.removenowords
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { removeNonWords } from 'strman'
19 | * // OR
20 | * import removeNonWords from 'strman.removenowords'
21 | * ```
22 | * @param {String} value The String!
23 | * @param {String} [replaced = ''] Value to replace.
24 | * @example
25 | * const title = '__strman../'
26 | * removeNonWords(title)
27 | * // => 'strman'
28 | * @returns {String} String without non word characters.
29 | */
30 | export default (value: string, replaced: string = ''): string => replace(value, '[^\\w]+', replaced)
31 |
--------------------------------------------------------------------------------
/src/removeright.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import endsWith from './endswith'
3 | import substr from './substr'
4 | /**
5 | * @module removeSpaces
6 | * @description
7 | * Returns a new string with the 'suffix' removed, if present.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the removeSpaces function
14 | * ```sh
15 | * yarn add strman.removespaces
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { removeSpaces } from 'strman'
20 | * // OR
21 | * import removeSpaces from 'strman.removespaces'
22 | * ```
23 | * @param {String} value The String!
24 | * @param {String} suffix String to remove on right.
25 | * @param {Boolean} [caseSensitive = true] If you need to caseSensitive.
26 | * @example
27 | * const title = 'strman'
28 | * removeRight(title, 'man')
29 | * // => 'str'
30 | * @returns {String} The String without suffix!
31 | */
32 | export default (value: string, suffix: string, caseSensitive: boolean = true): string => {
33 | if (endsWith(value, suffix, null, caseSensitive)) {
34 | const length = value.length - suffix.length
35 | return substr(value, 0, length)
36 | }
37 |
38 | return value
39 | }
40 |
--------------------------------------------------------------------------------
/src/removespaces.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import replace from './replace'
3 |
4 | /**
5 | * @module removeSpaces
6 | * @description
7 | * Remove all spaces and replace for value.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the removeSpaces function
14 | * ```sh
15 | * yarn add strman.removespaces
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { removeSpaces } from 'strman'
20 | * // OR
21 | * import removeSpaces from 'strman.removespaces'
22 | * ```
23 | * @param {String} value - The String!
24 | * @param {String} replaced - Value to replace.
25 | * @example
26 | * const title = ' s t r m a n '
27 | * removeSpaces(title)
28 | * // => 'strman'
29 | * @returns {String} String without spaces.
30 | */
31 | export default (value: string, replaced: string = ''): string => replace(value, '\\s+', replaced)
32 |
--------------------------------------------------------------------------------
/src/repeat.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module repeat
4 | * @description
5 | * Returns a repeated string given a multiplier.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the repeat function
12 | * ```sh
13 | * yarn add strman.repeat
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { repeat } from 'strman'
18 | * // OR
19 | * import repeat from 'strman.repeat'
20 | * ```
21 | * @param {String} value - The String!
22 | * @param {Number} multiplier - Number of repeats.
23 | * @example
24 | * const title = 'strman'
25 | * repeat(title, 5)
26 | * // => 'strmanstrmanstrmanstrmanstrman'
27 | * @returns {String} The String repeated!
28 | */
29 | export default (value: string, multiplier: number): string => {
30 | let i = 0
31 | let result = ''
32 | while (multiplier > i) {
33 | result += value
34 | i += 1
35 | }
36 | return result
37 | }
38 |
--------------------------------------------------------------------------------
/src/replace.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module replace
4 | * @description
5 | * Replace all ocurrences of 'search' value to 'newvalue'.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the replace function
12 | * ```sh
13 | * yarn add strman.replace
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { replace } from 'strman'
18 | * // OR
19 | * import replace from 'strman.replace'
20 | * ```
21 | * @param {String} value The String!
22 | * @param {String} search String to search.
23 | * @param {String} newvalue String to replace.
24 | * @param {Boolean} caseSensitive if you use caseSensitive replace.
25 | * @param {Boolean} multiline if you use multiline replace.
26 | * @example
27 | * const title = 'superman'
28 | * replace(title, 'upe', 't')
29 | * // => 'strman'
30 | * @returns {String} String replaced with 'newvalue'.
31 | */
32 | export default (
33 | value: string,
34 | search: string = '',
35 | newvalue: string | Function = '',
36 | caseSensitive: boolean = true,
37 | multiline: boolean = true,
38 | ): string => {
39 | const flags = caseSensitive ? 'g' : 'gi'
40 | const flagsMultiline = multiline ? `${flags}m` : flags
41 |
42 | return value.replace(new RegExp(search, flagsMultiline), newvalue)
43 | }
44 |
--------------------------------------------------------------------------------
/src/reverse.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import split from './split'
3 | import append from './append'
4 | /**
5 | * @module reverse
6 | * @description
7 | * Returns a reversed string.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the reverse function
14 | * ```sh
15 | * yarn add strman.reverse
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { reverse } from 'strman'
20 | * // OR
21 | * import reverse from 'strman.reverse'
22 | * ```
23 | * @param {String} value - The String!
24 | * @example
25 | * reverse('strman')
26 | * // => 'namrts'
27 | * @returns {String} The String reversed!
28 | */
29 | export default (value: string): string =>
30 | split(value, '').reduceRight((previous, current) => append(previous, current), '')
31 |
--------------------------------------------------------------------------------
/src/rightpad.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import substr from './substr'
3 | import append from './append'
4 |
5 | const rightPad = (value: string, length: number, char: string): string => {
6 | if (value.length === length) {
7 | return value
8 | }
9 | return rightPad(append(value, char), length, char)
10 | }
11 |
12 | /**
13 | * @module rightPad
14 | * @description
15 | * Returns a new string of a given length such that the ending of the string is padded.
16 | * ## Install
17 | * Install all functions of strman
18 | * ```sh
19 | * yarn add strman
20 | * ```
21 | * or just the rightPad function
22 | * ```sh
23 | * yarn add strman.rightpad
24 | * ```
25 | * ## Usage
26 | * ```javascript
27 | * import { rightPad } from 'strman'
28 | * // OR
29 | * import rightPad from 'strman.rightpad'
30 | * ```
31 | * @param {String} value The String!
32 | * @param {Number} _length Max length of String.
33 | * @param {Char} char Char to repeat.
34 | * @example
35 | * const title = "strman"
36 | * rightPad(title, 10, 0)
37 | * // => 'strman0000'
38 | * @returns {String} String pad.
39 | */
40 | export default (value: string, length: number, char: string = ' '): string =>
41 | rightPad(value, length, substr(String(char), 0, 1))
42 |
--------------------------------------------------------------------------------
/src/righttrim.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import replace from './replace'
3 |
4 | /**
5 | * @module rightTrim
6 | * @description
7 | * Remove all spaces on right.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the rightTrim function
14 | * ```sh
15 | * yarn add strman.righttrim
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { rightTrim } from 'strman'
20 | * // OR
21 | * import rightTrim from 'strman.righttrim'
22 | * ```
23 | * @param {String} value The String!
24 | * @param {String} [char = ' '] if you need remove other char on right boarders.
25 | * @example
26 | * const title = 'strman '
27 | * rightTrim(title)
28 | * // => 'strman'
29 | * @returns {String} String without right boarders spaces.
30 | */
31 | export default (value: string, char: string = ' '): string => replace(value, `${char}+$`, '')
32 |
--------------------------------------------------------------------------------
/src/safetruncate.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import _append from './append'
3 | import lastIndexOf from './lastindexof'
4 | import indexOf from './indexof'
5 | import substr from './substr'
6 |
7 | /**
8 | * @module safeTruncate
9 | * @description
10 | * Truncate the string securely, not cutting a word in half. It always returns the last full word.
11 | * ## Install
12 | * Install all functions of strman
13 | * ```sh
14 | * yarn add strman
15 | * ```
16 | * or just the safeTruncate function
17 | * ```sh
18 | * yarn add strman.safetruncate
19 | * ```
20 | * ## Usage
21 | * ```javascript
22 | * import { safeTruncate } from 'strman'
23 | * // OR
24 | * import safeTruncate from 'strman.safetruncate'
25 | * ```
26 | * @param {String} value Value will be truncated securely.
27 | * @param {Number} length Max size of the returned string.
28 | * @param {String} [append = ''] Value that will be added to the end of the return string.
29 | * @example
30 | * const title = 'A Javascript string manipulation library.'
31 | * safeTruncate(title, 15, '...');
32 | * // => 'A Javascript...'
33 | * @returns {String} String truncated safely.
34 | */
35 | export default (value: string, length: number, append: string = ''): string => {
36 | let truncated = ''
37 |
38 | if (length === 0) {
39 | return ''
40 | }
41 |
42 | if (length >= value.length) {
43 | return value
44 | }
45 |
46 | const newLength = length - append.length
47 | truncated = substr(value, 0, newLength)
48 |
49 | const position = indexOf(value, ' ', newLength - 1)
50 |
51 | if (position !== newLength) {
52 | const lastPos = lastIndexOf(truncated, ' ')
53 | truncated = substr(truncated, 0, lastPos)
54 | }
55 |
56 | return _append(truncated, append)
57 | }
58 |
--------------------------------------------------------------------------------
/src/shuffle.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import split from './split'
3 |
4 | const shuffle = (array: Array = []): Array => {
5 | let j
6 | let i
7 | const newArray = array
8 | for (i = array.length; i; i -= 1) {
9 | j = Math.floor(Math.random() * i)
10 | newArray[i - 1] = array[j]
11 | newArray[j] = array[i - 1]
12 | }
13 | return newArray
14 | }
15 |
16 | /**
17 | * @module shuffle
18 | * @description
19 | * It returns a string with its characters in random order.
20 | * ## Install
21 | * Install all functions of strman
22 | * ```sh
23 | * yarn add strman
24 | * ```
25 | * or just the shuffle function
26 | * ```sh
27 | * yarn add strman.shuffle
28 | * ```
29 | * ## Usage
30 | * ```javascript
31 | * import { shuffle } from 'strman'
32 | * // OR
33 | * import shuffle from 'strman.shuffle'
34 | * ```
35 | * @param {String} value The String!
36 | * @example
37 | * shuffle('strman')
38 | * // => 'rtmnas'
39 | * @returns {String} The String shuffled!
40 | */
41 | export default (value: string): string => shuffle(split(value)).join('')
42 |
--------------------------------------------------------------------------------
/src/slice.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module slugify
4 | * @description
5 | * Alias to slice method.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the slugify function
12 | * ```sh
13 | * yarn add strman.slugify
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { slugify } from 'strman'
18 | * // OR
19 | * import slugify from 'strman.slugify'
20 | * ```
21 | * @param {String} value The String!
22 | * @param {Number} beginSlice Start of slice.
23 | * @param {Number} endSlice End of slice.
24 | * @example
25 | * const title = 'strman'
26 | * slice(title, 2, 5)
27 | * // => 'rma'
28 | * @returns {String} The String sliced!
29 | */
30 | export default (value: string, beginSlice: number, endSlice: number = beginSlice): string =>
31 | value.slice(beginSlice, endSlice)
32 |
--------------------------------------------------------------------------------
/src/slugify.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toLowerCase from './tolowercase'
3 | import trim from './trim'
4 | import removeSpaces from './removespaces'
5 | import replace from './replace'
6 | import transliterate from './transliterate'
7 | /**
8 | * @module slugify
9 | * @description
10 | * Converts a value to a slug.
11 | * ## Install
12 | * Install all functions of strman
13 | * ```sh
14 | * yarn add strman
15 | * ```
16 | * or just the slugify function
17 | * ```sh
18 | * yarn add strman.slugify
19 | * ```
20 | * ## Usage
21 | * ```javascript
22 | * import { slugify } from 'strman'
23 | * // OR
24 | * import slugify from 'strman.slugify'
25 | * ```
26 | * @param {String} value The value to slugify
27 | * @example
28 | * const title = 'A Javascript string manipulation library.'
29 | * slugify(title)
30 | * // => 'a-javascript-string-manipulation-library'
31 | * @returns {String} The slugified value
32 | */
33 | export default (value: string): string => {
34 | const lowerCaseValue = toLowerCase(value)
35 | const trimValue = trim(lowerCaseValue)
36 | const valueWithoutSpaces = removeSpaces(trimValue, '-')
37 | const valueWithE = replace(valueWithoutSpaces, '&', '-and-')
38 | const transliterateValue = transliterate(valueWithE)
39 | const wordsOnlyValue = replace(transliterateValue, '[^\\w\\-]+', '')
40 | const singleDashesValue = replace(wordsOnlyValue, '-+', '-')
41 | return trim(singleDashesValue, '-')
42 | }
43 |
--------------------------------------------------------------------------------
/src/split.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module split
4 | * @description
5 | * Alias to split function.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the split function
12 | * ```sh
13 | * yarn add strman.split
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { split } from 'strman'
18 | * // OR
19 | * import split from 'strman.split'
20 | * ```
21 | * @param {String} value - The String!
22 | * @param {String} separator - Split separator.
23 | * @param {Number} limit - Split limit.
24 | * @example
25 | * split('strman', '')
26 | * // => ['s', 't', 'r', 'm', 'a', 'n']
27 | * @returns {String} The String splited!
28 | */
29 | export default (value: string, separator: string = '', limit: number = -1): Array =>
30 | value.split(separator, limit)
31 |
--------------------------------------------------------------------------------
/src/startswith.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import substr from './substr'
3 | import toCaseSensitive from './lib/case'
4 | /**
5 | * @module startsWith
6 | * @description
7 | * Test if 'value' starts with 'search'
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the startsWith function
14 | * ```sh
15 | * yarn add strman.startswith
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { startsWith } from 'strman'
20 | * // OR
21 | * import startsWith from 'strman.startswith'
22 | * ```
23 | * @param {String} value The String!
24 | * @param {String} search Value to search.
25 | * @param {Number} [position = 0] offset to search.
26 | * @param {Boolean} [caseSensitive = true] if you use caseSensitive to test.
27 | * @example
28 | * startsWith('strman', 'str')
29 | * // => true
30 | * @returns {Boolean} If 'value' startsWith 'search' return true, else false.
31 | */
32 | export default (
33 | value: string,
34 | search: string,
35 | position: number = 0,
36 | caseSensitive: boolean = true,
37 | ): boolean =>
38 | substr(toCaseSensitive(value, caseSensitive), position, search.length) ===
39 | toCaseSensitive(search, caseSensitive)
40 |
--------------------------------------------------------------------------------
/src/strman.js:
--------------------------------------------------------------------------------
1 | export chars from './chars'
2 | export ensureLeft from './ensureleft'
3 | export inequal from './inequal'
4 | export prepend from './prepend'
5 | export rightPad from './rightpad'
6 | export surround from './surround'
7 | export truncate from './truncate'
8 | export collapseWhitespace from './collapsewhitespace'
9 | export ensureRight from './ensureright'
10 | export insert from './insert'
11 | export prependArray from './prependarray'
12 | export rightTrim from './righttrim'
13 | export toCamelCase from './tocamelcase'
14 | export urlDecode from './urlDecode'
15 | export append from './append'
16 | export compare from './compare'
17 | export equal from './equal'
18 | export isLowerCase from './islowercase'
19 | export removeEmptyStrings from './removeemptystrings'
20 | export safeTruncate from './safetruncate'
21 | export toDecamelize from './todecamelize'
22 | export urlEncode from './urlencode'
23 | export appendArray from './appendarray'
24 | export contains from './contains'
25 | export first from './first'
26 | export isString from './isstring'
27 | export removeLeft from './removeleft'
28 | export shuffle from './shuffle'
29 | export toKebabCase from './tokebabcase'
30 | export at from './at'
31 | export containsAll from './containsall'
32 | export format from './format'
33 | export isUpperCase from './isuppercase'
34 | export removeNonWords from './removenonwords'
35 | export slice from './slice'
36 | export toLowerCase from './tolowercase'
37 | export base64decode from './base64decode'
38 | export containsAny from './containsany'
39 | export hexDecode from './hexdecode'
40 | export last from './last'
41 | export removeRight from './removeright'
42 | export slugify from './slugify'
43 | export toSnakeCase from './tosnakecase'
44 | export base64encode from './base64encode'
45 | export countSubstr from './countsubstr'
46 | export hexEncode from './hexencode'
47 | export lastIndexOf from './lastindexof'
48 | export removeSpaces from './removespaces'
49 | export split from './split'
50 | export toStudlyCaps from './tostudlycaps'
51 | export between from './between'
52 | export decDecode from './decdecode'
53 | export htmlDecode from './htmldecode'
54 | export leftPad from './leftpad'
55 | export repeat from './repeat'
56 | export startsWith from './startswith'
57 | export toUpperCase from './touppercase'
58 | export binDecode from './bindecode'
59 | export decEncode from './decencode'
60 | export htmlEncode from './htmlencode'
61 | export leftTrim from './lefttrim'
62 | export replace from './replace'
63 | export transliterate from './transliterate'
64 | export binEncode from './binencode'
65 | export endsWith from './endswith'
66 | export indexOf from './indexof'
67 | export reverse from './reverse'
68 | export substr from './substr'
69 | export trim from './trim'
70 |
71 | export default exports
72 |
--------------------------------------------------------------------------------
/src/substr.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module substr
4 | * @description
5 | * Alias to substr function.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the substr function
12 | * ```sh
13 | * yarn add strman.substr
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { substr } from 'strman'
18 | * // OR
19 | * import substr from 'strman.substr'
20 | * ```
21 | * @param {String} value - The String!
22 | * @param {Number} start - Substring starts.
23 | * @param {Number} length - Substring length.
24 | * @example
25 | * substr('strman', 0, 3)
26 | * // => 'strm'
27 | * @returns {String} The Substring!
28 | */
29 | export default (value: string, start: number, length: number): string =>
30 | value.substr(start, length)
31 |
--------------------------------------------------------------------------------
/src/surround.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import append from './append'
3 | /**
4 | * @module surround
5 | * @description
6 | * Surrounds a 'value' with the given 'substr'.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the surround function
13 | * ```sh
14 | * yarn add strman.surround
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { surround } from 'strman'
19 | * // OR
20 | * import surround from 'strman.surround'
21 | * ```
22 | * @param {String} value - The String!
23 | * @param {String} substr
24 | * The substr to append on left, if substrRight is null, this is appended in right.
25 | * @param {String} substrRight - The substr to append on right.
26 | * @example
27 | * surround('strman', '<', '>')
28 | * // => ''
29 | * @returns {String} The String with surround substrs!
30 | */
31 | export default (value: string, _substr: string = '', substrRight: ?string = null) =>
32 | append(_substr, value, substrRight === null ? _substr : substrRight)
33 |
--------------------------------------------------------------------------------
/src/tocamelcase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toStudlyCaps from './tostudlycaps'
3 | import toLowerCase from './tolowercase'
4 | /**
5 | * @module toCamelCase
6 | * @description
7 | * Transform to camelCase.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the toCamelCase function
14 | * ```sh
15 | * yarn add strman.tocamelcase
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { toCamelCase } from 'strman'
20 | * // OR
21 | * import toCamelCase from 'strman.tocamelcase'
22 | * ```
23 | * @param {String} value - The String!
24 | * @example
25 | * const title = 'A Javascript string manipulation library.'
26 | * toCamelCase(title)
27 | * // => 'aJavascriptStringManipulationLibrary'
28 | * @returns {String} String in camelCase.
29 | */
30 | export default (value: string): string => {
31 | const string = toStudlyCaps(value)
32 | return toLowerCase(string.substr(0, 1)) + string.substr(1)
33 | }
34 |
--------------------------------------------------------------------------------
/src/todecamelize.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toCamelCase from './tocamelcase'
3 | import toLowerCase from './tolowercase'
4 | /**
5 | * @module toDecamelize
6 | * @description
7 | * Decamelize String
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the toDecamelize function
14 | * ```sh
15 | * yarn add strman.todecamelize
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { toDecamelize } from 'strman'
20 | * // OR
21 | * import toDecamelize from 'strman.todecamelize'
22 | * ```
23 | * @param {String} value - The String!
24 | * @example
25 | * const title = 'A Javascript string manipulation library.'
26 | * toDecamelize(title)
27 | * // => 'a_javascript_string_manipulation_library.'
28 | * @returns {String} String decamelized.
29 | */
30 | export default (value: string, chr: string = '_'): string => {
31 | const camel = toCamelCase(value)
32 | const string = camel.replace(/([A-Z])+/g, `${chr}$1`)
33 | return toLowerCase(string)
34 | }
35 |
--------------------------------------------------------------------------------
/src/tokebabcase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toDecamelize from './todecamelize'
3 | /**
4 | * @module toKebabCase
5 | * @description
6 | * Transform to kebab-case.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the toKebabCase function
13 | * ```sh
14 | * yarn add strman.tokebabcase
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { toKebabCase } from 'strman'
19 | * // OR
20 | * import toKebabCase from 'strman.tokebabcase'
21 | * ```
22 | * @param {String} value The String!
23 | * @example
24 | * const title = 'A Javascript string manipulation library.'
25 | * toKebabCase(title)
26 | * // => 'a-javascript-string-manipulation-library.'
27 | * @returns {String} String in kebab-case.
28 | */
29 | export default (value: string): string => toDecamelize(value, '-')
30 |
--------------------------------------------------------------------------------
/src/tolowercase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module toLowerCase
4 | * @description
5 | * Transform to lowercase.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the toLowerCase function
12 | * ```sh
13 | * yarn add strman.tolowercase
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { toLowerCase } from 'strman'
18 | * // OR
19 | * import toLowerCase from 'strman.tolowercase'
20 | * ```
21 | * @param {String} value - The String!
22 | * @example
23 | * const title = 'A Javascript string manipulation library.'
24 | * toLowerCase(title)
25 | * // => 'a javascript string manipulation library.'
26 | * @returns {String} String in lowercase.
27 | */
28 | export default (value: string): string => value.toLowerCase()
29 |
--------------------------------------------------------------------------------
/src/tosnakecase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toDecamelize from './todecamelize'
3 | /**
4 | * @module toSnakeCase
5 | * @description
6 | * Transform to snake_case.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the toSnakeCase function
13 | * ```sh
14 | * yarn add strman.tosnakecase
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { toSnakeCase } from 'strman'
19 | * // OR
20 | * import toSnakeCase from 'strman.tosnakecase'
21 | * ```
22 | * @param {String} value The String!
23 | * @example
24 | * const title = 'A Javascript string manipulation library.'
25 | * toSnakeCase(title)
26 | * // => 'a_javascript_string_manipulation_library.'
27 | * @returns {String} String in snake_case.
28 | */
29 | export default (value: string): string => toDecamelize(value, '_')
30 |
--------------------------------------------------------------------------------
/src/tostudlycaps.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import toUpperCase from './touppercase'
3 | /**
4 | * @module toStudlyCaps
5 | * @description
6 | * Transform to StudlyCaps.
7 | * ## Install
8 | * Install all functions of strman
9 | * ```sh
10 | * yarn add strman
11 | * ```
12 | * or just the toStudlyCaps function
13 | * ```sh
14 | * yarn add strman.tostudlycaps
15 | * ```
16 | * ## Usage
17 | * ```javascript
18 | * import { toStudlyCaps } from 'strman'
19 | * // OR
20 | * import toStudlyCaps from 'strman.tostudlycaps'
21 | * ```
22 | * @param {String} value - The String!
23 | * @example
24 | * const title = 'A Javascript string manipulation library.'
25 | * toStudlyCaps(title)
26 | * // => 'AJavascriptStringManipulationLibrary.'
27 | * @returns {String} String in StudlyCaps.
28 | */
29 | export default (value: string): string => {
30 | const string = value.replace(/[-_\s]+(.)?/g, (match, chr) => toUpperCase(chr))
31 | return toUpperCase(string.substr(0, 1)) + string.substr(1)
32 | }
33 |
--------------------------------------------------------------------------------
/src/touppercase.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | /**
3 | * @module toUpperCase
4 | * @description
5 | * Transform to uppercase.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the toUpperCase function
12 | * ```sh
13 | * yarn add strman.touppercase
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { toUpperCase } from 'strman'
18 | * // OR
19 | * import toUpperCase from 'strman.touppercase'
20 | * ```
21 | * @param {String} value - The String!
22 | * @example
23 | * const title = 'A Javascript string manipulation library.'
24 | * toUpperCase(title)
25 | * // => 'A JAVASCRIPT STRING MANIPULATION LIBRARY.'
26 | * @returns {String} String in uppercase.
27 | */
28 | export default (value: string): string => value.toUpperCase()
29 |
--------------------------------------------------------------------------------
/src/transliterate.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import ascii from './lib/ascii'
3 | import replace from './replace'
4 |
5 | /**
6 | * @module transliterate
7 | * @description
8 | * Remove all non valid characters. Example: change á => a or ẽ => e.
9 | * ## Install
10 | * Install all functions of strman
11 | * ```sh
12 | * yarn add strman
13 | * ```
14 | * or just the transliterate function
15 | * ```sh
16 | * yarn add strman.transliterate
17 | * ```
18 | * ## Usage
19 | * ```javascript
20 | * import { transliterate } from 'strman'
21 | * // OR
22 | * import transliterate from 'strman.transliterate'
23 | * ```
24 | * @param {String} value - The String!
25 | * @example
26 | * const title = 'strmáñ'
27 | * transliterate(title)
28 | * // => 'strman'
29 | * @returns {String} String without non valid characters.
30 | */
31 | export default (value: string): string =>
32 | Object.keys(ascii).reduce(
33 | (newValue, currentKey) =>
34 | ascii[currentKey].reduce(
35 | (previous, currentValue) => replace(previous, currentValue, currentKey),
36 | newValue,
37 | ),
38 | value,
39 | )
40 |
--------------------------------------------------------------------------------
/src/trim.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import leftTrim from './lefttrim'
3 | import rightTrim from './righttrim'
4 |
5 | /**
6 | * @module trim
7 | * @description
8 | * Remove all spaces on left and right.
9 | * ## Install
10 | * Install all functions of strman
11 | * ```sh
12 | * yarn add strman
13 | * ```
14 | * or just the trim function
15 | * ```sh
16 | * yarn add strman.trim
17 | * ```
18 | * ## Usage
19 | * ```javascript
20 | * import { trim } from 'strman'
21 | * // OR
22 | * import trim from 'strman.trim'
23 | * ```
24 | * @param {String} value - String to remove spaces.
25 | * @param {String} [char = ' '] - if you need remove other char on boarders.
26 | * @example
27 | * const title = ' strman '
28 | * trim(title)
29 | * // => 'strman'
30 | * @returns {String} String without boarders spaces.
31 | */
32 | export default (value: string, char: string = ' '): string => leftTrim(rightTrim(value, char), char)
33 |
--------------------------------------------------------------------------------
/src/truncate.js:
--------------------------------------------------------------------------------
1 | // @form
2 | import substr from './substr'
3 | import append from './append'
4 | /**
5 | * @module truncate
6 | * @description
7 | * Truncate the unsecured form string, cutting the independent string of required position.
8 | * ## Install
9 | * Install all functions of strman
10 | * ```sh
11 | * yarn add strman
12 | * ```
13 | * or just the truncate function
14 | * ```sh
15 | * yarn add strman.truncate
16 | * ```
17 | * ## Usage
18 | * ```javascript
19 | * import { truncate } from 'strman'
20 | * // OR
21 | * import truncate from 'strman.truncate'
22 | * ```
23 | * @param {String} value - Value will be truncated unsecurely.
24 | * @param {Number} length - Size of the returned string.
25 | * @param {String} [_append = ''] - Value that will be added to the end of the return string.
26 | * @example
27 | * const title = 'A Javascript string manipulation library.'
28 | * truncate(title, 16, '...')
29 | * // => 'A Javascript ...'
30 | * @returns {String} String truncated unsafely.
31 | */
32 | export default (value: string, length: number, _append: string = ''): string => {
33 | if (length === 0) {
34 | return ''
35 | }
36 |
37 | if (length >= value.length) {
38 | return value
39 | }
40 |
41 | const truncated = substr(value, 0, length - _append.length)
42 |
43 | return append(truncated, _append)
44 | }
45 |
--------------------------------------------------------------------------------
/src/urlDecode.js:
--------------------------------------------------------------------------------
1 | // @form
2 | /**
3 | * @module urlDecode
4 | * @description
5 | * Decodes URL-encoded string
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the urlDecode function
12 | * ```sh
13 | * yarn add strman.urldecode
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { urlDecode } from 'strman'
18 | * // OR
19 | * import urlDecode from 'strman.urldecode'
20 | * ```
21 | * @param {String} value - The string to be decoded
22 | * @example
23 | * urlDecode('https://github.com/dleitee/strman/&name=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')
24 | * // => 'https://github.com/dleitee/strman/&name=áéíóú'
25 | * @returns {String} Returns the decoded string.
26 | */
27 | export default (value: string): string => decodeURI(value)
28 |
--------------------------------------------------------------------------------
/src/urlencode.js:
--------------------------------------------------------------------------------
1 | // @form
2 | /**
3 | * @module urlEncode
4 | * @description
5 | * Replaces all characters with the appropriate UTF-8 escape sequences.
6 | * ## Install
7 | * Install all functions of strman
8 | * ```sh
9 | * yarn add strman
10 | * ```
11 | * or just the urlEncode function
12 | * ```sh
13 | * yarn add strman.urlencode
14 | * ```
15 | * ## Usage
16 | * ```javascript
17 | * import { urlEncode } from 'strman'
18 | * // OR
19 | * import urlEncode from 'strman.urlencode'
20 | * ```
21 | * @param {String} value - The string to be encoded
22 | * @example
23 | * urlEncode('https://github.com/dleitee/strman/&name=áéíóú')
24 | * // => 'https://github.com/dleitee/strman/&name=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA'
25 | * @returns {String} Returns a string in which all non-alphanumeric characters except -_.
26 | */
27 | export default (value: string): string => encodeURI(value)
28 |
--------------------------------------------------------------------------------
/strman.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/strman.png
--------------------------------------------------------------------------------
/strman_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dleitee/strman/3f77a1cad7ffc01cc91195cf924d930149129f0f/strman_new.png
--------------------------------------------------------------------------------
/test/append.strman.test.js:
--------------------------------------------------------------------------------
1 | import { append } from '../src/strman'
2 |
3 | describe('strman.append', () => {
4 | test('should import append from strman', () => {
5 | expect(append('f', 'o', 'o', 'b', 'a', 'r')).toBe('foobar')
6 | expect(append('foobar')).toBe('foobar')
7 | expect(append('', 'foobar')).toBe('foobar')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/append.test.js:
--------------------------------------------------------------------------------
1 | import append from '../src/append'
2 | import { append as strmanAppend } from '../src/strman'
3 |
4 | describe('strman.append', () => {
5 | test('should be foobar', () => {
6 | expect(append('f', 'o', 'o', 'b', 'a', 'r')).toBe('foobar')
7 | expect(append('foobar')).toBe('foobar')
8 | expect(append('', 'foobar')).toBe('foobar')
9 | })
10 | })
11 |
12 | describe('strman.append', () => {
13 | test('should import append from strman', () => {
14 | expect(strmanAppend('f', 'o', 'o', 'b', 'a', 'r')).toBe('foobar')
15 | expect(strmanAppend('foobar')).toBe('foobar')
16 | expect(strmanAppend('', 'foobar')).toBe('foobar')
17 | })
18 | })
19 |
--------------------------------------------------------------------------------
/test/appendarray.strman.test.js:
--------------------------------------------------------------------------------
1 | import { appendArray } from '../src/strman'
2 |
3 | describe('strman.appendArray', () => {
4 | test('should import appendArray from strman', () => {
5 | expect(appendArray('f', ['o', 'o', 'b', 'a', 'r'])).toBe('foobar')
6 | expect(appendArray('foobar')).toBe('foobar')
7 | expect(appendArray('', ['foobar'])).toBe('foobar')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/appendarray.test.js:
--------------------------------------------------------------------------------
1 | import appendArray from '../src/appendarray'
2 |
3 | describe('strman.appendArray', () => {
4 | test('should be foobar', () => {
5 | expect(appendArray('f', ['o', 'o', 'b', 'a', 'r'])).toBe('foobar')
6 | expect(appendArray('foobar')).toBe('foobar')
7 | expect(appendArray('', ['foobar'])).toBe('foobar')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/at.strman.test.js:
--------------------------------------------------------------------------------
1 | import { at } from '../src/strman'
2 |
3 | describe('strman.at', () => {
4 | test('should import at from strman', () => {
5 | expect(at('foobar', 0)).toBe('f')
6 | expect(at('ofobar', 1)).toBe('f')
7 | expect(at('oobarf', -1)).toBe('f')
8 | expect(at('oobafr', -2)).toBe('f')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/at.test.js:
--------------------------------------------------------------------------------
1 | import at from '../src/at'
2 |
3 | describe('strman.at', () => {
4 | test('should be f', () => {
5 | expect(at('foobar', 0)).toBe('f')
6 | expect(at('ofobar', 1)).toBe('f')
7 | expect(at('oobarf', -1)).toBe('f')
8 | expect(at('oobafr', -2)).toBe('f')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/base64decode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { base64decode } from '../src/strman'
2 |
3 | describe('strman.base64decode', () => {
4 | test('should import base64decode from strman', () => {
5 | expect(base64decode('RGFuaWVs')).toBe('Daniel')
6 | expect(base64decode('Zm9v')).toBe('foo')
7 | expect(base64decode('YmFy')).toBe('bar')
8 | expect(base64decode('YsOhciE=')).toBe('bár!')
9 | expect(base64decode('5ryi')).toBe('漢')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/base64decode.test.js:
--------------------------------------------------------------------------------
1 | import base64decode from '../src/base64decode'
2 |
3 | describe('strman.base64decode', () => {
4 | test('should be a string decoded', () => {
5 | expect(base64decode('RGFuaWVs')).toBe('Daniel')
6 | expect(base64decode('Zm9v')).toBe('foo')
7 | expect(base64decode('YmFy')).toBe('bar')
8 | expect(base64decode('YsOhciE=')).toBe('bár!')
9 | expect(base64decode('5ryi')).toBe('漢')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/base64encode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { base64encode } from '../src/strman'
2 |
3 | describe('strman.base64encode', () => {
4 | test('should import base64decode from strman', () => {
5 | expect(base64encode('Daniel')).toBe('RGFuaWVs')
6 | expect(base64encode('foo')).toBe('Zm9v')
7 | expect(base64encode('bar')).toBe('YmFy')
8 | expect(base64encode('bár!')).toBe('YsOhciE=')
9 | expect(base64encode('漢')).toBe('5ryi')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/base64encode.test.js:
--------------------------------------------------------------------------------
1 | import base64encode from '../src/base64encode'
2 |
3 | describe('strman.base64encode', () => {
4 | test('should be a string encoded', () => {
5 | expect(base64encode('Daniel')).toBe('RGFuaWVs')
6 | expect(base64encode('foo')).toBe('Zm9v')
7 | expect(base64encode('bar')).toBe('YmFy')
8 | expect(base64encode('bár!')).toBe('YsOhciE=')
9 | expect(base64encode('漢')).toBe('5ryi')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/between.strman.test.js:
--------------------------------------------------------------------------------
1 | import between from '../src/between'
2 |
3 | describe('strman.between', () => {
4 | test('should be ["foo"]', () => {
5 | expect(between('[foo]', '[', ']')[0]).toBe('foo')
6 | expect(between('foo', '', '')[0]).toBe('foo')
7 | expect(between('barfoo', '', '')[0]).toBe('bar')
8 | expect(between('barfoo', '', '')[1]).toBe('foo')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/between.test.js:
--------------------------------------------------------------------------------
1 | import between from '../src/between'
2 |
3 | describe('strman.between', () => {
4 | test('should be ["foo"]', () => {
5 | expect(between('[foo]', '[', ']')[0]).toBe('foo')
6 | expect(between('foo', '', '')[0]).toBe('foo')
7 | expect(between('barfoo', '', '')[0]).toBe('bar')
8 | expect(between('barfoo', '', '')[1]).toBe('foo')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/bindecode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { binDecode } from '../src/strman'
2 |
3 | describe('strman.binDecode', () => {
4 | test('should be a string decoded', () => {
5 | expect(binDecode('0110111100100010')).toBe('漢')
6 | expect(binDecode('0000000001000001')).toBe('A')
7 | expect(binDecode('0000000011000001')).toBe('Á')
8 | expect(binDecode('00000000010000010000000001000001')).toBe('AA')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/bindecode.test.js:
--------------------------------------------------------------------------------
1 | import bindecode from '../src/bindecode'
2 |
3 | describe('strman.bindecode', () => {
4 | test('should be a string decoded', () => {
5 | expect(bindecode('0110111100100010')).toBe('漢')
6 | expect(bindecode('0000000001000001')).toBe('A')
7 | expect(bindecode('0000000011000001')).toBe('Á')
8 | expect(bindecode('00000000010000010000000001000001')).toBe('AA')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/binencode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { binEncode } from '../src/strman'
2 |
3 | describe('strman.binEncode', () => {
4 | test('should be a binary', () => {
5 | expect(binEncode('漢')).toBe('0110111100100010')
6 | expect(binEncode('A')).toBe('0000000001000001')
7 | expect(binEncode('Á')).toBe('0000000011000001')
8 | expect(binEncode('AA')).toBe('00000000010000010000000001000001')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/binencode.test.js:
--------------------------------------------------------------------------------
1 | import binencode from '../src/binencode'
2 |
3 | describe('strman.binencode', () => {
4 | test('should be a binary', () => {
5 | expect(binencode('漢')).toBe('0110111100100010')
6 | expect(binencode('A')).toBe('0000000001000001')
7 | expect(binencode('Á')).toBe('0000000011000001')
8 | expect(binencode('AA')).toBe('00000000010000010000000001000001')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/chars.strman.test.js:
--------------------------------------------------------------------------------
1 | import { chars } from '../src/strman'
2 |
3 | describe('strman.chars', () => {
4 | it('should be ["t", "i", "t", "l", "e"]', () => {
5 | const title = 'title'
6 | expect(chars(title)[0]).toBe('t')
7 | expect(chars(title)[1]).toBe('i')
8 | expect(chars(title)[2]).toBe('t')
9 | expect(chars(title)[3]).toBe('l')
10 | expect(chars(title)[4]).toBe('e')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/chars.test.js:
--------------------------------------------------------------------------------
1 | import chars from '../src/chars'
2 |
3 | describe('strman.chars', () => {
4 | it('should be ["t", "i", "t", "l", "e"]', () => {
5 | const title = 'title'
6 | expect(chars(title)[0]).toBe('t')
7 | expect(chars(title)[1]).toBe('i')
8 | expect(chars(title)[2]).toBe('t')
9 | expect(chars(title)[3]).toBe('l')
10 | expect(chars(title)[4]).toBe('e')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/collapsewhitespace.strman.test.js:
--------------------------------------------------------------------------------
1 | import { collapseWhitespace } from '../src/strman'
2 |
3 | describe('strman.collapseWhitespace', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['foo bar', ' foo bar ', ' foo bar ', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(collapseWhitespace(el)).toBe('foo bar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/collapsewhitespace.test.js:
--------------------------------------------------------------------------------
1 | import collapseWhitespace from '../src/collapsewhitespace'
2 |
3 | describe('strman.collapseWhitespace', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['foo bar', ' foo bar ', ' foo bar ', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(collapseWhitespace(el)).toBe('foo bar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/compare.strman.test.js:
--------------------------------------------------------------------------------
1 | import { compare } from '../src/strman'
2 |
3 | describe('strman.compare', () => {
4 | test('should be 1, -1, 0', () => {
5 | expect(compare('a', 'b')).toBe(-1)
6 | expect(compare('b', 'a')).toBe(1)
7 | expect(compare('a', 'a')).toBe(0)
8 | expect(compare('0', '1')).toBe(-1)
9 | expect(compare('1', '0')).toBe(1)
10 | expect(compare('0', '0')).toBe(0)
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/compare.test.js:
--------------------------------------------------------------------------------
1 | import compare from '../src/compare'
2 |
3 | describe('strman.compare', () => {
4 | test('should be 1, -1, 0', () => {
5 | expect(compare('a', 'b')).toBe(-1)
6 | expect(compare('b', 'a')).toBe(1)
7 | expect(compare('a', 'a')).toBe(0)
8 | expect(compare('0', '1')).toBe(-1)
9 | expect(compare('1', '0')).toBe(1)
10 | expect(compare('0', '0')).toBe(0)
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/contains.strman.test.js:
--------------------------------------------------------------------------------
1 | import { contains } from '../src/strman'
2 |
3 | describe('strman.contains', () => {
4 | test('should be true, caseSensitive = true', () => {
5 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(contains(el, 'foo', true)).toBe(true)
9 | })
10 | })
11 |
12 | test('should be true, caseSensitive = false', () => {
13 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
14 |
15 | fixtures.forEach((el) => {
16 | expect(contains(el, 'FOO', false)).toBe(true)
17 | })
18 | })
19 |
20 | test('should be false, caseSensitive = true', () => {
21 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
22 |
23 | fixtures.forEach((el) => {
24 | expect(contains(el, 'FOO', true)).toBe(false)
25 | })
26 | })
27 |
28 | test('should be false, caseSensitive = false', () => {
29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
30 |
31 | fixtures.forEach((el) => {
32 | expect(contains(el, 'dleitee', false)).toBe(false)
33 | })
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/test/contains.test.js:
--------------------------------------------------------------------------------
1 | import contains from '../src/contains'
2 |
3 | describe('strman.contains', () => {
4 | test('should be true, caseSensitive = true', () => {
5 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(contains(el, 'foo', true)).toBe(true)
9 | })
10 | })
11 |
12 | test('should be true, caseSensitive = false', () => {
13 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
14 |
15 | fixtures.forEach((el) => {
16 | expect(contains(el, 'FOO', false)).toBe(true)
17 | })
18 | })
19 |
20 | test('should be false, caseSensitive = true', () => {
21 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
22 |
23 | fixtures.forEach((el) => {
24 | expect(contains(el, 'FOO', true)).toBe(false)
25 | })
26 | })
27 |
28 | test('should be false, caseSensitive = false', () => {
29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
30 |
31 | fixtures.forEach((el) => {
32 | expect(contains(el, 'dleitee', false)).toBe(false)
33 | })
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/test/containsall.strman.test.js:
--------------------------------------------------------------------------------
1 | import { containsAll } from '../src/strman'
2 |
3 | describe('strman.containsAll', () => {
4 | test('should be true, if needle = []', () => {
5 | expect(containsAll('a', [], true)).toBe(false)
6 | })
7 |
8 | test('should be true, caseSensitive = true', () => {
9 | const fixtures = ['foo bar', 'bar foo', 'foobar']
10 |
11 | fixtures.forEach((el) => {
12 | expect(containsAll(el, ['foo', 'bar'], true)).toBe(true)
13 | })
14 | })
15 |
16 | test('should be true, caseSensitive = false', () => {
17 | const fixtures = ['foo bar', 'bar foo', 'foobar']
18 |
19 | fixtures.forEach((el) => {
20 | expect(containsAll(el, ['FOO', 'BAR'], false)).toBe(true)
21 | })
22 | })
23 |
24 | test('should be false, caseSensitive = true', () => {
25 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo']
26 |
27 | fixtures.forEach((el) => {
28 | expect(containsAll(el, ['FOO', 'BAR'], true)).toBe(false)
29 | })
30 | })
31 |
32 | test('should be false, caseSensitive = false', () => {
33 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
34 |
35 | fixtures.forEach((el) => {
36 | expect(containsAll(el, ['foo', 'bar', 'dleitee'], false)).toBe(false)
37 | })
38 | })
39 | })
40 |
--------------------------------------------------------------------------------
/test/containsall.test.js:
--------------------------------------------------------------------------------
1 | import containsAll from '../src/containsall'
2 |
3 | describe('strman.containsAll', () => {
4 | test('should be true, if needle = []', () => {
5 | expect(containsAll('a', [], true)).toBe(false)
6 | })
7 |
8 | test('should be true, caseSensitive = true', () => {
9 | const fixtures = ['foo bar', 'bar foo', 'foobar']
10 |
11 | fixtures.forEach((el) => {
12 | expect(containsAll(el, ['foo', 'bar'], true)).toBe(true)
13 | })
14 | })
15 |
16 | test('should be true, caseSensitive = false', () => {
17 | const fixtures = ['foo bar', 'bar foo', 'foobar']
18 |
19 | fixtures.forEach((el) => {
20 | expect(containsAll(el, ['FOO', 'BAR'], false)).toBe(true)
21 | })
22 | })
23 |
24 | test('should be false, caseSensitive = true', () => {
25 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo']
26 |
27 | fixtures.forEach((el) => {
28 | expect(containsAll(el, ['FOO', 'BAR'], true)).toBe(false)
29 | })
30 | })
31 |
32 | test('should be false, caseSensitive = false', () => {
33 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
34 |
35 | fixtures.forEach((el) => {
36 | expect(containsAll(el, ['foo', 'bar', 'dleitee'], false)).toBe(false)
37 | })
38 | })
39 | })
40 |
--------------------------------------------------------------------------------
/test/containsany.strman.test.js:
--------------------------------------------------------------------------------
1 | import { containsAny } from '../src/strman'
2 |
3 | describe('strman.containsAny', () => {
4 | test('should be true, caseSensitive = true', () => {
5 | const fixtures = ['foo bar', 'bar foo', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(containsAny(el, ['foo', 'bar', 'test'], true)).toBe(true)
9 | })
10 | })
11 |
12 | test('should be true, caseSensitive = false', () => {
13 | const fixtures = ['foo bar', 'bar foo', 'foobar']
14 |
15 | fixtures.forEach((el) => {
16 | expect(containsAny(el, ['FOO', 'BAR', 'Test'], false)).toBe(true)
17 | })
18 | })
19 |
20 | test('should be false, caseSensitive = true', () => {
21 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo']
22 |
23 | fixtures.forEach((el) => {
24 | expect(containsAny(el, ['FOO', 'BAR', 'TEST'], true)).toBe(false)
25 | })
26 | })
27 |
28 | test('should be false, caseSensitive = false', () => {
29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
30 |
31 | fixtures.forEach((el) => {
32 | expect(containsAny(el, ['dleitee'], false)).toBe(false)
33 | })
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/test/containsany.test.js:
--------------------------------------------------------------------------------
1 | import containsAny from '../src/containsany'
2 |
3 | describe('strman.containsAny', () => {
4 | test('should be true, caseSensitive = true', () => {
5 | const fixtures = ['foo bar', 'bar foo', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(containsAny(el, ['foo', 'bar', 'test'], true)).toBe(true)
9 | })
10 | })
11 |
12 | test('should be true, caseSensitive = false', () => {
13 | const fixtures = ['foo bar', 'bar foo', 'foobar']
14 |
15 | fixtures.forEach((el) => {
16 | expect(containsAny(el, ['FOO', 'BAR', 'Test'], false)).toBe(true)
17 | })
18 | })
19 |
20 | test('should be false, caseSensitive = true', () => {
21 | const fixtures = ['foo', 'bar foo', 'foobar', 'foo']
22 |
23 | fixtures.forEach((el) => {
24 | expect(containsAny(el, ['FOO', 'BAR', 'TEST'], true)).toBe(false)
25 | })
26 | })
27 |
28 | test('should be false, caseSensitive = false', () => {
29 | const fixtures = ['foo bar', 'bar foo', 'foobar', 'foo']
30 |
31 | fixtures.forEach((el) => {
32 | expect(containsAny(el, ['dleitee'], false)).toBe(false)
33 | })
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/test/countsubstr.strman.test.js:
--------------------------------------------------------------------------------
1 | import { countSubstr } from '../src/strman'
2 |
3 | describe('strman.countSubstr', () => {
4 | test('should be 7', () => {
5 | const fixtures = ['aaaaaAaaAA', 'faaaAAaaaaAA', 'aaAAaaaaafA', 'AAaaafaaaaAAAA']
6 |
7 | fixtures.forEach((el) => {
8 | expect(countSubstr(el, 'a')).toBe(7)
9 | })
10 | })
11 |
12 | test('should be 7 without caseSensitive', () => {
13 | const fixtures = ['aaaaaaa', 'faaaaaaa', 'aaaaaaaf', 'aaafaaaa']
14 |
15 | fixtures.forEach((el) => {
16 | expect(countSubstr(el, 'A', false)).toBe(7)
17 | })
18 | })
19 |
20 | test('should be 2 with allowOverlaping', () => {
21 | expect(countSubstr('aaa', 'aa', true, true)).toBe(2)
22 | })
23 |
24 | test('should be 1 without allowOverlaping', () => {
25 | expect(countSubstr('aaa', 'aa', true, false)).toBe(1)
26 | })
27 | })
28 |
--------------------------------------------------------------------------------
/test/countsubstr.test.js:
--------------------------------------------------------------------------------
1 | import countSubstr from '../src/countsubstr'
2 |
3 | describe('strman.countSubstr', () => {
4 | test('should be 7', () => {
5 | const fixtures = ['aaaaaAaaAA', 'faaaAAaaaaAA', 'aaAAaaaaafA', 'AAaaafaaaaAAAA']
6 |
7 | fixtures.forEach((el) => {
8 | expect(countSubstr(el, 'a')).toBe(7)
9 | })
10 | })
11 |
12 | test('should be 7 without caseSensitive', () => {
13 | const fixtures = ['aaaaaaa', 'faaaaaaa', 'aaaaaaaf', 'aaafaaaa']
14 |
15 | fixtures.forEach((el) => {
16 | expect(countSubstr(el, 'A', false)).toBe(7)
17 | })
18 | })
19 |
20 | test('should be 2 with allowOverlaping', () => {
21 | expect(countSubstr('aaa', 'aa', true, true)).toBe(2)
22 | })
23 |
24 | test('should be 1 without allowOverlaping', () => {
25 | expect(countSubstr('aaa', 'aa', true, false)).toBe(1)
26 | })
27 | })
28 |
--------------------------------------------------------------------------------
/test/decdecode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { decDecode } from '../src/strman'
2 |
3 | describe('strman.decDecode', () => {
4 | test('should be string', () => {
5 | expect(decDecode('28450')).toBe('漢')
6 | expect(decDecode('00065')).toBe('A')
7 | expect(decDecode('00193')).toBe('Á')
8 | expect(decDecode('0006500065')).toBe('AA')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/decdecode.test.js:
--------------------------------------------------------------------------------
1 | import decDecode from '../src/decdecode'
2 |
3 | describe('strman.decDecode', () => {
4 | test('should be string', () => {
5 | expect(decDecode('28450')).toBe('漢')
6 | expect(decDecode('00065')).toBe('A')
7 | expect(decDecode('00193')).toBe('Á')
8 | expect(decDecode('0006500065')).toBe('AA')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/decencode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { decEncode } from '../src/strman'
2 |
3 | describe('strman.decEncode', () => {
4 | test('should be binary', () => {
5 | expect(decEncode('漢')).toBe('28450')
6 | expect(decEncode('A')).toBe('00065')
7 | expect(decEncode('Á')).toBe('00193')
8 | expect(decEncode('AA')).toBe('0006500065')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/decencode.test.js:
--------------------------------------------------------------------------------
1 | import decEncode from '../src/decencode'
2 |
3 | describe('strman.decEncode', () => {
4 | test('should be binary', () => {
5 | expect(decEncode('漢')).toBe('28450')
6 | expect(decEncode('A')).toBe('00065')
7 | expect(decEncode('Á')).toBe('00193')
8 | expect(decEncode('AA')).toBe('0006500065')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/endswith.strman.test.js:
--------------------------------------------------------------------------------
1 | import { endsWith } from '../src/strman'
2 |
3 | describe('strman.endsWith', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foo bar', 'bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(endsWith(el, 'bar')).toBe(true)
9 | })
10 |
11 | const fixtures2 = ['foo barr', 'barr']
12 |
13 | fixtures2.forEach((el) => {
14 | expect(endsWith(el, 'bar', el.length - 1)).toBe(true)
15 | })
16 | })
17 | })
18 |
19 | describe('strman.endsWith caseSensitive', () => {
20 | test('should be true', () => {
21 | const fixtures = ['foo bar', 'bar']
22 |
23 | fixtures.forEach((el) => {
24 | expect(endsWith(el, 'BAR', null, false)).toBe(true)
25 | })
26 |
27 | const fixtures2 = ['foo barr', 'barr']
28 |
29 | fixtures2.forEach((el) => {
30 | expect(endsWith(el, 'BAR', el.length - 1, false)).toBe(true)
31 | })
32 | })
33 | })
34 |
--------------------------------------------------------------------------------
/test/endswith.test.js:
--------------------------------------------------------------------------------
1 | import endsWith from '../src/endswith'
2 |
3 | describe('strman.endsWith', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foo bar', 'bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(endsWith(el, 'bar')).toBe(true)
9 | })
10 |
11 | const fixtures2 = ['foo barr', 'barr']
12 |
13 | fixtures2.forEach((el) => {
14 | expect(endsWith(el, 'bar', el.length - 1)).toBe(true)
15 | })
16 | })
17 | })
18 |
19 | describe('strman.endsWith caseSensitive', () => {
20 | test('should be true', () => {
21 | const fixtures = ['foo bar', 'bar']
22 |
23 | fixtures.forEach((el) => {
24 | expect(endsWith(el, 'BAR', null, false)).toBe(true)
25 | })
26 |
27 | const fixtures2 = ['foo barr', 'barr']
28 |
29 | fixtures2.forEach((el) => {
30 | expect(endsWith(el, 'BAR', el.length - 1, false)).toBe(true)
31 | })
32 | })
33 | })
34 |
--------------------------------------------------------------------------------
/test/ensureleft.strman.test.js:
--------------------------------------------------------------------------------
1 | import { ensureLeft } from '../src/strman'
2 |
3 | describe('strman.ensureLeft', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['bar', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(ensureLeft(el, 'foo')).toBe('foobar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/ensureleft.test.js:
--------------------------------------------------------------------------------
1 | import ensureLeft from '../src/ensureleft'
2 |
3 | describe('strman.ensureLeft', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['bar', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(ensureLeft(el, 'foo')).toBe('foobar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/ensureright.strman.test.js:
--------------------------------------------------------------------------------
1 | import { ensureRight } from '../src/strman'
2 |
3 | describe('strman.ensureRight', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['foo', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(ensureRight(el, 'bar')).toBe('foobar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/ensureright.test.js:
--------------------------------------------------------------------------------
1 | import ensureRight from '../src/ensureright'
2 |
3 | describe('strman.ensureRight', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['foo', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(ensureRight(el, 'bar')).toBe('foobar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/equal.strman.test.js:
--------------------------------------------------------------------------------
1 | import { equal } from '../src/strman'
2 |
3 | describe('strman.equal', () => {
4 | test('should be true or false', () => {
5 | expect(equal('a', 'b')).toBe(false)
6 | expect(equal('a', 'a')).toBe(true)
7 | expect(equal('0', 0)).toBe(false)
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/equal.test.js:
--------------------------------------------------------------------------------
1 | import equal from '../src/equal'
2 |
3 | describe('strman.equal', () => {
4 | test('should be true or false', () => {
5 | expect(equal('a', 'b')).toBe(false)
6 | expect(equal('a', 'a')).toBe(true)
7 | expect(equal('0', 0)).toBe(false)
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/first.strman.test.js:
--------------------------------------------------------------------------------
1 | import { first } from '../src/strman'
2 |
3 | describe('strman.first', () => {
4 | test('should be foo', () => {
5 | const fixtures = ['foo', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(first(el, 3)).toBe('foo')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/first.test.js:
--------------------------------------------------------------------------------
1 | import first from '../src/first'
2 |
3 | describe('strman.first', () => {
4 | test('should be foo', () => {
5 | const fixtures = ['foo', 'foobar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(first(el, 3)).toBe('foo')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/format.strman.test.js:
--------------------------------------------------------------------------------
1 | import { format } from '../src/strman'
2 |
3 | describe('strman.format', () => {
4 | test('should be formated strings', () => {
5 | expect(format('foo bar')).toBe('foo bar')
6 | expect(format('{0} bar', ['foo'])).toBe('foo bar')
7 | expect(format('foo {0}', ['bar'])).toBe('foo bar')
8 | expect(format('foo {0}', ['bar', 'foo'])).toBe('foo bar')
9 | expect(format('{0} {1}', ['foo', 'bar'])).toBe('foo bar')
10 | expect(format('{1} {0}', ['bar', 'foo'])).toBe('foo bar')
11 | expect(format('{1} {0}', ['bar'])).toBe('{1} bar')
12 | expect(format('{foo} bar', { foo: 'foo' })).toBe('foo bar')
13 | expect(format('{foo} {bar}', {
14 | foo: 'foo',
15 | bar: 'bar',
16 | })).toBe('foo bar')
17 | })
18 |
19 | test('should be {0}', () => {
20 | expect(format('foo bar {0}')).toBe('foo bar {0}')
21 | })
22 | })
23 |
--------------------------------------------------------------------------------
/test/format.test.js:
--------------------------------------------------------------------------------
1 | import format from '../src/format'
2 |
3 | describe('strman.format', () => {
4 | test('should be formated strings', () => {
5 | expect(format('foo bar')).toBe('foo bar')
6 | expect(format('{0} bar', ['foo'])).toBe('foo bar')
7 | expect(format('foo {0}', ['bar'])).toBe('foo bar')
8 | expect(format('foo {0}', ['bar', 'foo'])).toBe('foo bar')
9 | expect(format('{0} {1}', ['foo', 'bar'])).toBe('foo bar')
10 | expect(format('{1} {0}', ['bar', 'foo'])).toBe('foo bar')
11 | expect(format('{1} {0}', ['bar'])).toBe('{1} bar')
12 | expect(format('{foo} bar', { foo: 'foo' })).toBe('foo bar')
13 | expect(format('{foo} {bar}', {
14 | foo: 'foo',
15 | bar: 'bar',
16 | })).toBe('foo bar')
17 | })
18 |
19 | test('should be {0}', () => {
20 | expect(format('foo bar {0}')).toBe('foo bar {0}')
21 | })
22 | })
23 |
--------------------------------------------------------------------------------
/test/hexdecode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { hexDecode } from '../src/strman'
2 |
3 | describe('strman.hexDecode', () => {
4 | test('should be string', () => {
5 | expect(hexDecode('6f22')).toBe('漢')
6 | expect(hexDecode('0041')).toBe('A')
7 | expect(hexDecode('00c1')).toBe('Á')
8 | expect(hexDecode('00410041')).toBe('AA')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/hexdecode.test.js:
--------------------------------------------------------------------------------
1 | import hexDecode from '../src/hexdecode'
2 |
3 | describe('strman.hexDecode', () => {
4 | test('should be string', () => {
5 | expect(hexDecode('6f22')).toBe('漢')
6 | expect(hexDecode('0041')).toBe('A')
7 | expect(hexDecode('00c1')).toBe('Á')
8 | expect(hexDecode('00410041')).toBe('AA')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/hexencode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { hexEncode } from '../src/strman'
2 |
3 | describe('strman.hexEncode', () => {
4 | test('should be hexadecimal', () => {
5 | expect(hexEncode('漢')).toBe('6f22')
6 | expect(hexEncode('A')).toBe('0041')
7 | expect(hexEncode('Á')).toBe('00c1')
8 | expect(hexEncode('AA')).toBe('00410041')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/hexencode.test.js:
--------------------------------------------------------------------------------
1 | import hexEncode from '../src/hexencode'
2 |
3 | describe('strman.hexEncode', () => {
4 | test('should be hexadecimal', () => {
5 | expect(hexEncode('漢')).toBe('6f22')
6 | expect(hexEncode('A')).toBe('0041')
7 | expect(hexEncode('Á')).toBe('00c1')
8 | expect(hexEncode('AA')).toBe('00410041')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/htmldecode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { htmlDecode } from '../src/strman'
2 |
3 | describe('strman.htmlDecode', () => {
4 | test('should be decoded html', () => {
5 | expect(htmlDecode('á')).toBe('\u00E1')
6 | expect(htmlDecode('Ш')).toBe('Ш')
7 | expect(htmlDecode('Ж')).toBe('Ж')
8 | expect(htmlDecode('┐')).toBe('┐')
9 | expect(htmlDecode('&boxdlaaa;')).toBe('&boxdlaaa;')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/htmldecode.test.js:
--------------------------------------------------------------------------------
1 | import htmlDecode from '../src/htmldecode'
2 |
3 | describe('strman.htmlDecode', () => {
4 | test('should be decoded html', () => {
5 | expect(htmlDecode('á')).toBe('\u00E1')
6 | expect(htmlDecode('Ш')).toBe('Ш')
7 | expect(htmlDecode('Ж')).toBe('Ж')
8 | expect(htmlDecode('┐')).toBe('┐')
9 | expect(htmlDecode('&boxdlaaa;')).toBe('&boxdlaaa;')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/htmlencode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { htmlEncode } from '../src/strman'
2 |
3 | describe('strman.htmlEncode', () => {
4 | test('should be encoded html', () => {
5 | expect(htmlEncode('á')).toBe('á')
6 | expect(htmlEncode('áéíóú')).toBe('áéíóú')
7 | expect(htmlEncode('Ш')).toBe('Ш')
8 | expect(htmlEncode('Ж')).toBe('Ж')
9 | expect(htmlEncode('┐')).toBe('┐')
10 | expect(htmlEncode('a')).toBe('a')
11 | expect(htmlEncode('¶')).toBe('¶')
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/test/htmlencode.test.js:
--------------------------------------------------------------------------------
1 | import htmlEncode from '../src/htmlencode'
2 |
3 | describe('strman.htmlEncode', () => {
4 | test('should be encoded html', () => {
5 | expect(htmlEncode('á')).toBe('á')
6 | expect(htmlEncode('áéíóú')).toBe('áéíóú')
7 | expect(htmlEncode('Ш')).toBe('Ш')
8 | expect(htmlEncode('Ж')).toBe('Ж')
9 | expect(htmlEncode('┐')).toBe('┐')
10 | expect(htmlEncode('a')).toBe('a')
11 | expect(htmlEncode('¶')).toBe('¶')
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/test/indexof.strman.test.js:
--------------------------------------------------------------------------------
1 | import { indexOf } from '../src/strman'
2 |
3 | describe('strman.indexOf', () => {
4 | test('should be true', () => {
5 | const value = 'foobar'
6 | expect(indexOf(value, 'f')).toBe(0)
7 | expect(indexOf(value, 'o')).toBe(1)
8 | expect(indexOf(value, 'b')).toBe(3)
9 | expect(indexOf(value, 'a')).toBe(4)
10 | expect(indexOf(value, 'r')).toBe(5)
11 | expect(indexOf(value, 't')).toBe(-1)
12 | })
13 | })
14 |
15 | describe('strman.indexOf caseSensitive', () => {
16 | test('should be true', () => {
17 | const value = 'FOOBAR'
18 | expect(indexOf(value, 'f', undefined, false)).toBe(0)
19 | expect(indexOf(value, 'o', undefined, false)).toBe(1)
20 | expect(indexOf(value, 'b', undefined, false)).toBe(3)
21 | expect(indexOf(value, 'a', undefined, false)).toBe(4)
22 | expect(indexOf(value, 'r', undefined, false)).toBe(5)
23 | expect(indexOf(value, 't', undefined, false)).toBe(-1)
24 | })
25 | })
26 |
--------------------------------------------------------------------------------
/test/indexof.test.js:
--------------------------------------------------------------------------------
1 | import indexOf from '../src/indexof'
2 |
3 | describe('strman.indexOf', () => {
4 | test('should be true', () => {
5 | const value = 'foobar'
6 | expect(indexOf(value, 'f')).toBe(0)
7 | expect(indexOf(value, 'o')).toBe(1)
8 | expect(indexOf(value, 'b')).toBe(3)
9 | expect(indexOf(value, 'a')).toBe(4)
10 | expect(indexOf(value, 'r')).toBe(5)
11 | expect(indexOf(value, 't')).toBe(-1)
12 | })
13 | })
14 |
15 | describe('strman.indexOf caseSensitive', () => {
16 | test('should be true', () => {
17 | const value = 'FOOBAR'
18 | expect(indexOf(value, 'f', undefined, false)).toBe(0)
19 | expect(indexOf(value, 'o', undefined, false)).toBe(1)
20 | expect(indexOf(value, 'b', undefined, false)).toBe(3)
21 | expect(indexOf(value, 'a', undefined, false)).toBe(4)
22 | expect(indexOf(value, 'r', undefined, false)).toBe(5)
23 | expect(indexOf(value, 't', undefined, false)).toBe(-1)
24 | })
25 | })
26 |
--------------------------------------------------------------------------------
/test/inequal.strman.test.js:
--------------------------------------------------------------------------------
1 | import { inequal } from '../src/strman'
2 |
3 | describe('strman.inequal', () => {
4 | test('should be true or false', () => {
5 | expect(inequal('a', 'b')).toBe(true)
6 | expect(inequal('a', 'a')).toBe(false)
7 | expect(inequal('0', 0)).toBe(true)
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/inequal.test.js:
--------------------------------------------------------------------------------
1 | import inequal from '../src/inequal'
2 |
3 | describe('strman.inequal', () => {
4 | test('should be true or false', () => {
5 | expect(inequal('a', 'b')).toBe(true)
6 | expect(inequal('a', 'a')).toBe(false)
7 | expect(inequal('0', 0)).toBe(true)
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/insert.strman.test.js:
--------------------------------------------------------------------------------
1 | import { insert } from '../src/strman'
2 |
3 | describe('strman.insert', () => {
4 | test('should be foo bar', () => {
5 | expect(insert('fbar', 'oo ', 1)).toBe('foo bar')
6 | expect(insert('foo', ' bar', 3)).toBe('foo bar')
7 | expect(insert('foo bar', 'asadasd', 13)).toBe('foo bar')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/insert.test.js:
--------------------------------------------------------------------------------
1 | import insert from '../src/insert'
2 |
3 | describe('strman.insert', () => {
4 | test('should be foo bar', () => {
5 | expect(insert('fbar', 'oo ', 1)).toBe('foo bar')
6 | expect(insert('foo', ' bar', 3)).toBe('foo bar')
7 | expect(insert('foo bar', 'asadasd', 13)).toBe('foo bar')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/islowercase.strman.test.js:
--------------------------------------------------------------------------------
1 | import { isLowerCase } from '../src/strman'
2 |
3 | describe('strman.isLowerCase', () => {
4 | test('should be true', () => {
5 | const fixtures = ['', 'foo', 'foobarfoo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(isLowerCase(el)).toBe(true)
9 | })
10 | })
11 | test('should be false', () => {
12 | const fixtures = ['fooA', 'foobarfoAo']
13 |
14 | fixtures.forEach((el) => {
15 | expect(isLowerCase(el)).toBe(false)
16 | })
17 | })
18 | })
19 |
--------------------------------------------------------------------------------
/test/islowercase.test.js:
--------------------------------------------------------------------------------
1 | import isLowerCase from '../src/islowercase'
2 |
3 | describe('strman.isLowerCase', () => {
4 | test('should be true', () => {
5 | const fixtures = ['', 'foo', 'foobarfoo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(isLowerCase(el)).toBe(true)
9 | })
10 | })
11 | test('should be false', () => {
12 | const fixtures = ['fooA', 'foobarfoAo']
13 |
14 | fixtures.forEach((el) => {
15 | expect(isLowerCase(el)).toBe(false)
16 | })
17 | })
18 | })
19 |
--------------------------------------------------------------------------------
/test/isstring.strman.test.js:
--------------------------------------------------------------------------------
1 | import { isString } from '../src/strman'
2 |
3 | describe('strman.isString', () => {
4 | test('should be false', () => {
5 | const fixtures = [1, false, 1.2, [], {}]
6 | fixtures.forEach((el) => {
7 | expect(isString(el)).toBe(false)
8 | })
9 | })
10 |
11 | test('should be true', () => {
12 | const fixtures = ['string', '', 'áéíóú']
13 | fixtures.forEach((el) => {
14 | expect(isString(el)).toBe(true)
15 | })
16 | })
17 | })
18 |
--------------------------------------------------------------------------------
/test/isstring.test.js:
--------------------------------------------------------------------------------
1 | import isString from '../src/isstring'
2 |
3 | describe('strman.isString', () => {
4 | test('should be false', () => {
5 | const fixtures = [1, false, 1.2, [], {}]
6 | fixtures.forEach((el) => {
7 | expect(isString(el)).toBe(false)
8 | })
9 | })
10 |
11 | test('should be true', () => {
12 | const fixtures = ['string', '', 'áéíóú']
13 | fixtures.forEach((el) => {
14 | expect(isString(el)).toBe(true)
15 | })
16 | })
17 | })
18 |
--------------------------------------------------------------------------------
/test/isuppercase.strman.test.js:
--------------------------------------------------------------------------------
1 | import { isUpperCase } from '../src/strman'
2 |
3 | describe('strman.isUpperCase', () => {
4 | test('should be true', () => {
5 | const fixtures = ['', 'FOO', 'FOOBARFOO']
6 |
7 | fixtures.forEach((el) => {
8 | expect(isUpperCase(el)).toBe(true)
9 | })
10 | })
11 | test('should be false', () => {
12 | const fixtures = ['FOOa', 'FOOBARFOOa']
13 |
14 | fixtures.forEach((el) => {
15 | expect(isUpperCase(el)).toBe(false)
16 | })
17 | })
18 | })
19 |
--------------------------------------------------------------------------------
/test/isuppercase.test.js:
--------------------------------------------------------------------------------
1 | import isUpperCase from '../src/isuppercase'
2 |
3 | describe('strman.isUpperCase', () => {
4 | test('should be true', () => {
5 | const fixtures = ['', 'FOO', 'FOOBARFOO']
6 |
7 | fixtures.forEach((el) => {
8 | expect(isUpperCase(el)).toBe(true)
9 | })
10 | })
11 | test('should be false', () => {
12 | const fixtures = ['FOOa', 'FOOBARFOOa']
13 |
14 | fixtures.forEach((el) => {
15 | expect(isUpperCase(el)).toBe(false)
16 | })
17 | })
18 | })
19 |
--------------------------------------------------------------------------------
/test/last.strman.test.js:
--------------------------------------------------------------------------------
1 | import { last } from '../src/strman'
2 |
3 | describe('strman.last', () => {
4 | test('should be foo', () => {
5 | const fixtures = ['foo', 'foobarfoo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(last(el, 3)).toBe('foo')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/last.test.js:
--------------------------------------------------------------------------------
1 | import last from '../src/last'
2 |
3 | describe('strman.last', () => {
4 | test('should be foo', () => {
5 | const fixtures = ['foo', 'foobarfoo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(last(el, 3)).toBe('foo')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/lastindexof.strman.test.js:
--------------------------------------------------------------------------------
1 | import { lastIndexOf } from '../src/strman'
2 |
3 | describe('strman.lastIndexOf', () => {
4 | test('should be true', () => {
5 | const value = 'foobarfoobar'
6 | expect(lastIndexOf(value, 'f')).toBe(6)
7 | expect(lastIndexOf(value, 'o')).toBe(8)
8 | expect(lastIndexOf(value, 'b')).toBe(9)
9 | expect(lastIndexOf(value, 'a')).toBe(10)
10 | expect(lastIndexOf(value, 'r')).toBe(11)
11 | expect(lastIndexOf(value, 't')).toBe(-1)
12 | })
13 | })
14 |
15 | describe('strman.lastIndexOf caseSensitive', () => {
16 | test('should be true', () => {
17 | const value = 'foobarfoobar'
18 | expect(lastIndexOf(value, 'F', undefined, false)).toBe(6)
19 | expect(lastIndexOf(value, 'O', undefined, false)).toBe(8)
20 | expect(lastIndexOf(value, 'B', undefined, false)).toBe(9)
21 | expect(lastIndexOf(value, 'A', undefined, false)).toBe(10)
22 | expect(lastIndexOf(value, 'R', undefined, false)).toBe(11)
23 | expect(lastIndexOf(value, 'T', undefined, false)).toBe(-1)
24 | })
25 | })
26 |
--------------------------------------------------------------------------------
/test/lastindexof.test.js:
--------------------------------------------------------------------------------
1 | import lastIndexOf from '../src/lastindexof'
2 |
3 | describe('strman.lastIndexOf', () => {
4 | test('should be true', () => {
5 | const value = 'foobarfoobar'
6 | expect(lastIndexOf(value, 'f')).toBe(6)
7 | expect(lastIndexOf(value, 'o')).toBe(8)
8 | expect(lastIndexOf(value, 'b')).toBe(9)
9 | expect(lastIndexOf(value, 'a')).toBe(10)
10 | expect(lastIndexOf(value, 'r')).toBe(11)
11 | expect(lastIndexOf(value, 't')).toBe(-1)
12 | })
13 | })
14 |
15 | describe('strman.lastIndexOf caseSensitive', () => {
16 | test('should be true', () => {
17 | const value = 'foobarfoobar'
18 | expect(lastIndexOf(value, 'F', undefined, false)).toBe(6)
19 | expect(lastIndexOf(value, 'O', undefined, false)).toBe(8)
20 | expect(lastIndexOf(value, 'B', undefined, false)).toBe(9)
21 | expect(lastIndexOf(value, 'A', undefined, false)).toBe(10)
22 | expect(lastIndexOf(value, 'R', undefined, false)).toBe(11)
23 | expect(lastIndexOf(value, 'T', undefined, false)).toBe(-1)
24 | })
25 | })
26 |
--------------------------------------------------------------------------------
/test/leftpad.strman.test.js:
--------------------------------------------------------------------------------
1 | import { leftPad } from '../src/strman'
2 |
3 | describe('strman.leftPad', () => {
4 | test('should be a string 00001', () => {
5 | expect(leftPad('1', 5, '00')).toBe('00001')
6 | expect(leftPad('1', 5, 0)).toBe('00001')
7 | expect(leftPad('01', 5, 0)).toBe('00001')
8 | expect(leftPad('001', 5, 0)).toBe('00001')
9 | expect(leftPad('0001', 5, 0)).toBe('00001')
10 | expect(leftPad('00001', 5, 0)).toBe('00001')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/leftpad.test.js:
--------------------------------------------------------------------------------
1 | import leftpad from '../src/leftpad'
2 |
3 | describe('strman.leftpad', () => {
4 | test('should be a string 00001', () => {
5 | expect(leftpad('1', 5, '00')).toBe('00001')
6 | expect(leftpad('1', 5, 0)).toBe('00001')
7 | expect(leftpad('01', 5, 0)).toBe('00001')
8 | expect(leftpad('001', 5, 0)).toBe('00001')
9 | expect(leftpad('0001', 5, 0)).toBe('00001')
10 | expect(leftpad('00001', 5, 0)).toBe('00001')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/lefttrim.strman.test.js:
--------------------------------------------------------------------------------
1 | import { leftTrim } from '../src/strman'
2 |
3 | describe('strman.leftTrim', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['foo bar ', ' foo bar ', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(leftTrim(el)).toBe('foo bar ')
9 | })
10 | })
11 |
12 | test('should be foo bar without @', () => {
13 | const fixtures = ['foo bar@', '@foo bar@', '@@@foo bar@']
14 |
15 | fixtures.forEach((el) => {
16 | expect(leftTrim(el, '@')).toBe('foo bar@')
17 | })
18 | })
19 |
20 | test('should be foo bar without @ and with #', () => {
21 | const fixtures = ['@#foo bar@', '@#foo bar@', '@@#foo bar@']
22 |
23 | fixtures.forEach((el) => {
24 | expect(leftTrim(el, '@')).toBe('#foo bar@')
25 | })
26 | })
27 | })
28 |
--------------------------------------------------------------------------------
/test/lefttrim.test.js:
--------------------------------------------------------------------------------
1 | import lefttrim from '../src/lefttrim'
2 |
3 | describe('strman.lefttrim', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['foo bar ', ' foo bar ', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(lefttrim(el)).toBe('foo bar ')
9 | })
10 | })
11 |
12 | test('should be foo bar without @', () => {
13 | const fixtures = ['foo bar@', '@foo bar@', '@@@foo bar@']
14 |
15 | fixtures.forEach((el) => {
16 | expect(lefttrim(el, '@')).toBe('foo bar@')
17 | })
18 | })
19 |
20 | test('should be foo bar without @ and with #', () => {
21 | const fixtures = ['@#foo bar@', '@#foo bar@', '@@#foo bar@']
22 |
23 | fixtures.forEach((el) => {
24 | expect(lefttrim(el, '@')).toBe('#foo bar@')
25 | })
26 | })
27 | })
28 |
--------------------------------------------------------------------------------
/test/prepend.strman.test.js:
--------------------------------------------------------------------------------
1 | import { prepend } from '../src/strman'
2 |
3 | describe('strman.prepend', () => {
4 | test('should be foobar', () => {
5 | expect(prepend('r', 'f', 'o', 'o', 'b', 'a')).toBe('foobar')
6 | expect(prepend('foobar')).toBe('foobar')
7 | expect(prepend('', 'foobar')).toBe('foobar')
8 | expect(prepend('bar', 'foo')).toBe('foobar')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/prepend.test.js:
--------------------------------------------------------------------------------
1 | import prepend from '../src/prepend'
2 |
3 | describe('strman.prepend', () => {
4 | test('should be foobar', () => {
5 | expect(prepend('r', 'f', 'o', 'o', 'b', 'a')).toBe('foobar')
6 | expect(prepend('foobar')).toBe('foobar')
7 | expect(prepend('', 'foobar')).toBe('foobar')
8 | expect(prepend('bar', 'foo')).toBe('foobar')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/prependarray.strman.test.js:
--------------------------------------------------------------------------------
1 | import { prependArray } from '../src/strman'
2 |
3 | describe('strman.prependArray', () => {
4 | test('should be foobar', () => {
5 | expect(prependArray('r', ['f', 'o', 'o', 'b', 'a'])).toBe('foobar')
6 | expect(prependArray('foobar')).toBe('foobar')
7 | expect(prependArray('', ['foobar'])).toBe('foobar')
8 | expect(prependArray('bar', ['foo'])).toBe('foobar')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/prependarray.test.js:
--------------------------------------------------------------------------------
1 | import prependArray from '../src/prependarray'
2 |
3 | describe('strman.prependArray', () => {
4 | test('should be foobar', () => {
5 | expect(prependArray('r', ['f', 'o', 'o', 'b', 'a'])).toBe('foobar')
6 | expect(prependArray('foobar')).toBe('foobar')
7 | expect(prependArray('', ['foobar'])).toBe('foobar')
8 | expect(prependArray('bar', ['foo'])).toBe('foobar')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/removeemptystrings.strman.test.js:
--------------------------------------------------------------------------------
1 | import { removeEmptyStrings } from '../src/strman'
2 |
3 | describe('strman.removeEmptyStrings', () => {
4 | test('should be [\'aa\', \'bb\', \'cc\' ]', () => {
5 | expect(removeEmptyStrings(['aa', '', 'bb', null, 'cc', undefined])).toMatchObject(['aa', 'bb', 'cc'])
6 | })
7 | })
8 |
--------------------------------------------------------------------------------
/test/removeemptystrings.test.js:
--------------------------------------------------------------------------------
1 | import removeEmptyStrings from '../src/removeemptystrings'
2 |
3 | describe('strman.removeEmptyStrings', () => {
4 | test('should be [\'aa\', \'bb\', \'cc\' ]', () => {
5 | expect(removeEmptyStrings(['aa', '', 'bb', null, 'cc', undefined])).toMatchObject(['aa', 'bb', 'cc'])
6 | })
7 | })
8 |
--------------------------------------------------------------------------------
/test/removeleft.strman.test.js:
--------------------------------------------------------------------------------
1 | import { removeLeft } from '../src/strman'
2 |
3 | describe('strman.removeLeft', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foobar', 'bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeLeft(el, 'foo')).toBe('bar')
9 | })
10 | })
11 |
12 | test('should be Foobar', () => {
13 | expect(removeLeft('Foobar', 'foo')).toBe('Foobar')
14 | })
15 |
16 | test('should be bar', () => {
17 | expect(removeLeft('Foobar', 'foo', false)).toBe('bar')
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/test/removeleft.test.js:
--------------------------------------------------------------------------------
1 | import removeLeft from '../src/removeleft'
2 |
3 | describe('strman.removeLeft', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foobar', 'bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeLeft(el, 'foo')).toBe('bar')
9 | })
10 | })
11 |
12 | test('should be Foobar', () => {
13 | expect(removeLeft('Foobar', 'foo')).toBe('Foobar')
14 | })
15 |
16 | test('should be bar', () => {
17 | expect(removeLeft('Foobar', 'foo', false)).toBe('bar')
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/test/removenonwords.strman.test.js:
--------------------------------------------------------------------------------
1 | import { removeNonWords } from '../src/strman'
2 |
3 | describe('strman.removeNonWords', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['foo bar', 'foo&bar-']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeNonWords(el)).toBe('foobar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/removenonwords.test.js:
--------------------------------------------------------------------------------
1 | import removeNonWords from '../src/removenonwords'
2 |
3 | describe('strman.removeNonWords', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['foo bar', 'foo&bar-']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeNonWords(el)).toBe('foobar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/removeright.strman.test.js:
--------------------------------------------------------------------------------
1 | import { removeRight } from '../src/strman'
2 |
3 | describe('strman.removeRight', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foobar', 'foo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeRight(el, 'bar')).toBe('foo')
9 | })
10 |
11 | expect(removeRight('foofoofoobar', 'bar')).toBe('foofoofoo')
12 | expect(removeRight('foofoofoobar', 'foobar')).toBe('foofoo')
13 | })
14 | })
15 |
--------------------------------------------------------------------------------
/test/removeright.test.js:
--------------------------------------------------------------------------------
1 | import removeRight from '../src/removeright'
2 |
3 | describe('strman.removeRight', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foobar', 'foo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeRight(el, 'bar')).toBe('foo')
9 | })
10 |
11 | expect(removeRight('foofoofoobar', 'bar')).toBe('foofoofoo')
12 | expect(removeRight('foofoofoobar', 'foobar')).toBe('foofoo')
13 | })
14 | })
15 |
--------------------------------------------------------------------------------
/test/removespaces.strman.test.js:
--------------------------------------------------------------------------------
1 | import { removeSpaces } from '../src/strman'
2 |
3 | describe('strman.removeSpaces', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeSpaces(el)).toBe('foobar')
9 | })
10 | })
11 |
12 | test('should be foo-bar', () => {
13 | const fixtures = ['foo bar']
14 |
15 | fixtures.forEach((el) => {
16 | expect(removeSpaces(el, '-')).toBe('foo-bar')
17 | })
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/test/removespaces.test.js:
--------------------------------------------------------------------------------
1 | import removeSpaces from '../src/removespaces'
2 |
3 | describe('strman.removeSpaces', () => {
4 | test('should be foobar', () => {
5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(removeSpaces(el)).toBe('foobar')
9 | })
10 | })
11 |
12 | test('should be foo-bar', () => {
13 | const fixtures = ['foo bar']
14 |
15 | fixtures.forEach((el) => {
16 | expect(removeSpaces(el, '-')).toBe('foo-bar')
17 | })
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/test/repeat.strman.test.js:
--------------------------------------------------------------------------------
1 | import { repeat } from '../src/strman'
2 |
3 | describe('strman.repeat', () => {
4 | test('should be 1 repeated', () => {
5 | expect(repeat('1', 1)).toBe('1')
6 | expect(repeat('1', 2)).toBe('11')
7 | expect(repeat('1', 3)).toBe('111')
8 | expect(repeat('1', 4)).toBe('1111')
9 | expect(repeat('1', 5)).toBe('11111')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/repeat.test.js:
--------------------------------------------------------------------------------
1 | import repeat from '../src/repeat'
2 |
3 | describe('strman.repeat', () => {
4 | test('should be 1 repeated', () => {
5 | expect(repeat('1', 1)).toBe('1')
6 | expect(repeat('1', 2)).toBe('11')
7 | expect(repeat('1', 3)).toBe('111')
8 | expect(repeat('1', 4)).toBe('1111')
9 | expect(repeat('1', 5)).toBe('11111')
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/replace.strman.test.js:
--------------------------------------------------------------------------------
1 | import { replace } from '../src/strman'
2 |
3 | describe('strman.replace', () => {
4 | test('should be bar bar', () => {
5 | const fixtures = ['foo bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(replace(el, 'foo', 'bar')).toBe('bar bar')
9 | })
10 | })
11 | test('should be bar bar bar', () => {
12 | const fixtures = ['foo bar foo']
13 |
14 | fixtures.forEach((el) => {
15 | expect(replace(el, 'foo', 'bar')).toBe('bar bar bar')
16 | })
17 | })
18 | })
19 |
20 | describe('strman.replace - caseSensitive', () => {
21 | test('should be bar bar', () => {
22 | const fixtures = ['FOO bar']
23 |
24 | fixtures.forEach((el) => {
25 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar')
26 | })
27 | })
28 | test('should be bar bar bar', () => {
29 | const fixtures = ['FOO bar foo']
30 |
31 | fixtures.forEach((el) => {
32 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar bar')
33 | })
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/test/replace.test.js:
--------------------------------------------------------------------------------
1 | import replace from '../src/replace'
2 |
3 | describe('strman.replace', () => {
4 | test('should be bar bar', () => {
5 | const fixtures = ['foo bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(replace(el, 'foo', 'bar')).toBe('bar bar')
9 | })
10 | })
11 | test('should be bar bar bar', () => {
12 | const fixtures = ['foo bar foo']
13 |
14 | fixtures.forEach((el) => {
15 | expect(replace(el, 'foo', 'bar')).toBe('bar bar bar')
16 | })
17 | })
18 | })
19 |
20 | describe('strman.replace - caseSensitive', () => {
21 | test('should be bar bar', () => {
22 | const fixtures = ['FOO bar']
23 |
24 | fixtures.forEach((el) => {
25 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar')
26 | })
27 | })
28 | test('should be bar bar bar', () => {
29 | const fixtures = ['FOO bar foo']
30 |
31 | fixtures.forEach((el) => {
32 | expect(replace(el, 'foo', 'bar', false)).toBe('bar bar bar')
33 | })
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/test/reverse.strman.test.js:
--------------------------------------------------------------------------------
1 | import { reverse } from '../src/strman'
2 |
3 | describe('strman.reverse', () => {
4 | test('should be strings reverse', () => {
5 | expect(reverse('foo')).toBe('oof')
6 | expect(reverse('daniel')).toBe('leinad')
7 | expect(reverse('')).toBe('')
8 | expect(reverse('bar')).toBe('rab')
9 | expect(reverse('foo_')).toBe('_oof')
10 | expect(reverse('f')).toBe('f')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/reverse.test.js:
--------------------------------------------------------------------------------
1 | import reverse from '../src/reverse'
2 |
3 | describe('strman.reverse', () => {
4 | test('should be strings reverse', () => {
5 | expect(reverse('foo')).toBe('oof')
6 | expect(reverse('daniel')).toBe('leinad')
7 | expect(reverse('')).toBe('')
8 | expect(reverse('bar')).toBe('rab')
9 | expect(reverse('foo_')).toBe('_oof')
10 | expect(reverse('f')).toBe('f')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/rightpad.strman.test.js:
--------------------------------------------------------------------------------
1 | import { rightPad } from '../src/strman'
2 |
3 | describe('strman.rightPad', () => {
4 | test('should be 10000', () => {
5 | expect(rightPad('1', 5, '00')).toBe('10000')
6 | expect(rightPad('1', 5, 0)).toBe('10000')
7 | expect(rightPad('10', 5, 0)).toBe('10000')
8 | expect(rightPad('100', 5, 0)).toBe('10000')
9 | expect(rightPad('1000', 5, 0)).toBe('10000')
10 | expect(rightPad('10000', 5, 0)).toBe('10000')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/rightpad.test.js:
--------------------------------------------------------------------------------
1 | import rightPad from '../src/rightpad'
2 |
3 | describe('strman.rightPad', () => {
4 | test('should be 10000', () => {
5 | expect(rightPad('1', 5, '00')).toBe('10000')
6 | expect(rightPad('1', 5, 0)).toBe('10000')
7 | expect(rightPad('10', 5, 0)).toBe('10000')
8 | expect(rightPad('100', 5, 0)).toBe('10000')
9 | expect(rightPad('1000', 5, 0)).toBe('10000')
10 | expect(rightPad('10000', 5, 0)).toBe('10000')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/righttrim.strman.test.js:
--------------------------------------------------------------------------------
1 | import { rightTrim } from '../src/strman'
2 |
3 | describe('strman.rightTrim', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = [' foo bar', ' foo bar ', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(rightTrim(el)).toBe(' foo bar')
9 | })
10 | })
11 |
12 | test('should be foo bar without @', () => {
13 | const fixtures = ['foo bar@', 'foo bar@@@@@']
14 |
15 | fixtures.forEach((el) => {
16 | expect(rightTrim(el, '@')).toBe('foo bar')
17 | })
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/test/righttrim.test.js:
--------------------------------------------------------------------------------
1 | import righttrim from '../src/righttrim'
2 |
3 | describe('strman.righttrim', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = [' foo bar', ' foo bar ', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(righttrim(el)).toBe(' foo bar')
9 | })
10 | })
11 |
12 | test('should be foo bar without @', () => {
13 | const fixtures = ['foo bar@', 'foo bar@@@@@']
14 |
15 | fixtures.forEach((el) => {
16 | expect(righttrim(el, '@')).toBe('foo bar')
17 | })
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/test/safetruncate.strman.test.js:
--------------------------------------------------------------------------------
1 | import { safeTruncate } from '../src/strman'
2 |
3 | describe('strman.safeTruncate', () => {
4 | test('should be strings safeTruncated', () => {
5 | expect(safeTruncate('foo bar', 0, '.')).toBe('')
6 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.')
7 | expect(safeTruncate('foo bar', 3, '.')).toBe('.')
8 | expect(safeTruncate('foo bar', 2, '.')).toBe('.')
9 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.')
10 | expect(safeTruncate('foo bar', 7, '.')).toBe('foo bar')
11 | expect(safeTruncate('foo bar', 8, '.')).toBe('foo bar')
12 | expect(safeTruncate('A Javascript string manipulation library.', 16, '...')).toBe('A Javascript...')
13 | expect(safeTruncate('A Javascript string manipulation library.', 15, '...')).toBe('A Javascript...')
14 | expect(safeTruncate('A Javascript string manipulation library.', 14, '...')).toBe('A...')
15 | })
16 | })
17 |
--------------------------------------------------------------------------------
/test/safetruncate.test.js:
--------------------------------------------------------------------------------
1 | import safeTruncate from '../src/safetruncate'
2 |
3 | describe('strman.safeTruncate', () => {
4 | test('should be strings safeTruncated', () => {
5 | expect(safeTruncate('foo bar', 0, '.')).toBe('')
6 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.')
7 | expect(safeTruncate('foo bar', 3, '.')).toBe('.')
8 | expect(safeTruncate('foo bar', 2, '.')).toBe('.')
9 | expect(safeTruncate('foo bar', 4, '.')).toBe('foo.')
10 | expect(safeTruncate('foo bar', 7, '.')).toBe('foo bar')
11 | expect(safeTruncate('foo bar', 8, '.')).toBe('foo bar')
12 | expect(safeTruncate('A Javascript string manipulation library.', 16, '...')).toBe('A Javascript...')
13 | expect(safeTruncate('A Javascript string manipulation library.', 15, '...')).toBe('A Javascript...')
14 | expect(safeTruncate('A Javascript string manipulation library.', 14, '...')).toBe('A...')
15 | })
16 | })
17 |
--------------------------------------------------------------------------------
/test/shuffle.strman.test.js:
--------------------------------------------------------------------------------
1 | import { shuffle } from '../src/strman'
2 |
3 | describe('strman.shuffle', () => {
4 | test('should be strings shuffle', () => {
5 | expect(shuffle('foo').length).toBe(3)
6 | expect(shuffle('daniel').length).toBe(6)
7 | expect(shuffle('')).toBe('')
8 | expect(shuffle('b')).toBe('b')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/shuffle.test.js:
--------------------------------------------------------------------------------
1 | import shuffle from '../src/shuffle'
2 |
3 | describe('strman.shuffle', () => {
4 | test('should be strings shuffle', () => {
5 | expect(shuffle('foo').length).toBe(3)
6 | expect(shuffle('daniel').length).toBe(6)
7 | expect(shuffle('')).toBe('')
8 | expect(shuffle('b')).toBe('b')
9 | })
10 | })
11 |
--------------------------------------------------------------------------------
/test/slice.strman.test.js:
--------------------------------------------------------------------------------
1 | import { slice } from '../src/strman'
2 |
3 | describe('strman.slice', () => {
4 | test('should be foobar', () => {
5 | expect(slice('foobar', 0, 6)).toBe('foobar')
6 | expect(slice('foobar', 1, 5)).toBe('ooba')
7 | expect(slice('foobar', 2, 4)).toBe('ob')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/slice.test.js:
--------------------------------------------------------------------------------
1 | import slice from '../src/slice'
2 |
3 | describe('strman.slice', () => {
4 | test('should be foobar', () => {
5 | expect(slice('foobar', 0, 6)).toBe('foobar')
6 | expect(slice('foobar', 1, 5)).toBe('ooba')
7 | expect(slice('foobar', 2, 4)).toBe('ob')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/slugify.strman.test.js:
--------------------------------------------------------------------------------
1 | import { slugify } from '../src/strman'
2 |
3 | describe('strman.slugfiy', () => {
4 | test('should be foo-bar', () => {
5 | const fixtures = ['foo bar', 'foo bar.', 'foo bar ', ' foo bar', ' foo bar ', 'foo------bar', 'fóõ bár', 'foo ! bar', 'foo ~~ bar', 'foo bar', 'FOO bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(slugify(el)).toBe('foo-bar')
9 | })
10 | })
11 | test('should be foo-and-bar', () => {
12 | const fixtures = ['foo&bar', 'foo&bar.', 'foo&bar ', ' foo&bar', ' foo&bar ', 'foo&bar', 'fóõ-and---bár', 'foo & bar', 'FOO & bar']
13 |
14 | fixtures.forEach((el) => {
15 | expect(slugify(el)).toBe('foo-and-bar')
16 | })
17 | })
18 |
19 | test('should be throw', () => {
20 | const fixtures = [1, [], {}, 1.2, false, true]
21 |
22 | fixtures.forEach((el) => {
23 | expect(() => {
24 | slugify(el)
25 | }).toThrow(Error)
26 | })
27 | })
28 | })
29 |
--------------------------------------------------------------------------------
/test/slugify.test.js:
--------------------------------------------------------------------------------
1 | import slugify from '../src/slugify'
2 |
3 | describe('strman.slugfiy', () => {
4 | test('should be foo-bar', () => {
5 | const fixtures = ['foo bar', 'foo bar.', 'foo bar ', 'foo bar .', ' foo bar', ' foo bar ', 'foo------bar', 'fóõ bár', 'foo ! bar', 'foo ~~ bar', 'foo bar', 'FOO bar']
6 |
7 | fixtures.forEach((el) => {
8 | expect(slugify(el)).toBe('foo-bar')
9 | })
10 | })
11 | test('should be foo-and-bar', () => {
12 | const fixtures = ['foo&bar', 'foo&bar.', 'foo&bar ', ' foo&bar', ' foo&bar ', 'foo&bar', 'fóõ-and---bár', 'foo & bar', 'FOO & bar']
13 |
14 | fixtures.forEach((el) => {
15 | expect(slugify(el)).toBe('foo-and-bar')
16 | })
17 | })
18 |
19 | test('should be throw', () => {
20 | const fixtures = [1, [], {}, 1.2, false, true]
21 |
22 | fixtures.forEach((el) => {
23 | expect(() => {
24 | slugify(el)
25 | }).toThrow(Error)
26 | })
27 | })
28 | })
29 |
--------------------------------------------------------------------------------
/test/split.strman.test.js:
--------------------------------------------------------------------------------
1 | import { split } from '../src/strman'
2 |
3 | describe('strman.split', () => {
4 | test('should be [f o o]', () => {
5 | expect(split('foo')).toEqual(['f', 'o', 'o'])
6 | })
7 | test('should be [f o]', () => {
8 | expect(split('foo', '', 2)).toEqual(['f', 'o'])
9 | })
10 | test('should be [foo bar]', () => {
11 | expect(split('foo bar', ' ')).toEqual(['foo', 'bar'])
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/test/split.test.js:
--------------------------------------------------------------------------------
1 | import split from '../src/split'
2 |
3 | describe('strman.split', () => {
4 | test('should be [f o o]', () => {
5 | expect(split('foo')).toEqual(['f', 'o', 'o'])
6 | })
7 | test('should be [f o]', () => {
8 | expect(split('foo', '', 2)).toEqual(['f', 'o'])
9 | })
10 | test('should be [foo bar]', () => {
11 | expect(split('foo bar', ' ')).toEqual(['foo', 'bar'])
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/test/startswith.strman.test.js:
--------------------------------------------------------------------------------
1 | import { startsWith } from '../src/strman'
2 |
3 | describe('strman.startsWith', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foo bar', 'foobar', 'foo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(startsWith(el, 'foo')).toBe(true)
9 | })
10 |
11 | const fixtures2 = ['afoo barr', 'afoo']
12 |
13 | fixtures2.forEach((el) => {
14 | expect(startsWith(el, 'foo', 1)).toBe(true)
15 | })
16 | })
17 | })
18 |
19 | describe('strman.startsWith caseSensitive', () => {
20 | test('should be true', () => {
21 | const fixtures = ['foo bar', 'foobar', 'foo']
22 |
23 | fixtures.forEach((el) => {
24 | expect(startsWith(el, 'FOO', 0, false)).toBe(true)
25 | })
26 |
27 | const fixtures2 = ['afoo barr', 'afoo']
28 |
29 | fixtures2.forEach((el) => {
30 | expect(startsWith(el, 'FOO', 1, false)).toBe(true)
31 | })
32 | })
33 | })
34 |
--------------------------------------------------------------------------------
/test/startswith.test.js:
--------------------------------------------------------------------------------
1 | import startsWith from '../src/startswith'
2 |
3 | describe('strman.startsWith', () => {
4 | test('should be true', () => {
5 | const fixtures = ['foo bar', 'foobar', 'foo']
6 |
7 | fixtures.forEach((el) => {
8 | expect(startsWith(el, 'foo')).toBe(true)
9 | })
10 |
11 | const fixtures2 = ['afoo barr', 'afoo']
12 |
13 | fixtures2.forEach((el) => {
14 | expect(startsWith(el, 'foo', 1)).toBe(true)
15 | })
16 | })
17 | })
18 |
19 | describe('strman.startsWith caseSensitive', () => {
20 | test('should be true', () => {
21 | const fixtures = ['foo bar', 'foobar', 'foo']
22 |
23 | fixtures.forEach((el) => {
24 | expect(startsWith(el, 'FOO', 0, false)).toBe(true)
25 | })
26 |
27 | const fixtures2 = ['afoo barr', 'afoo']
28 |
29 | fixtures2.forEach((el) => {
30 | expect(startsWith(el, 'FOO', 1, false)).toBe(true)
31 | })
32 | })
33 | })
34 |
--------------------------------------------------------------------------------
/test/surround.strman.test.js:
--------------------------------------------------------------------------------
1 | import { surround } from '../src/strman'
2 |
3 | describe('strman.surround', () => {
4 | test('should be strings surround', () => {
5 | expect(surround('foo', 'bar')).toBe('barfoobar')
6 | expect(surround('daniel', '_')).toBe('_daniel_')
7 | expect(surround('', '>')).toBe('>>')
8 | expect(surround('bar', '')).toBe('bar')
9 | expect(surround('f')).toBe('f')
10 | expect(surround('div', '<', '>')).toBe('')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/surround.test.js:
--------------------------------------------------------------------------------
1 | import surround from '../src/surround'
2 |
3 | describe('strman.surround', () => {
4 | test('should be strings surround', () => {
5 | expect(surround('foo', 'bar')).toBe('barfoobar')
6 | expect(surround('daniel', '_')).toBe('_daniel_')
7 | expect(surround('', '>')).toBe('>>')
8 | expect(surround('bar', '')).toBe('bar')
9 | expect(surround('f')).toBe('f')
10 | expect(surround('div', '<', '>')).toBe('
')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/tocamelcase.strman.test.js:
--------------------------------------------------------------------------------
1 | import { toCamelCase } from '../src/strman'
2 |
3 | describe('strman.toCamelCase', () => {
4 | test('should match camelCase', () => {
5 | const fixtures = ['CamelCase', 'camelCase', 'Camel case', 'Camel case', 'camel Case', 'camel-case', '-camel--case', 'camel_case', ' camel_case']
6 |
7 | fixtures.forEach((el) => {
8 | expect(toCamelCase(el)).toBe('camelCase')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/tocamelcase.test.js:
--------------------------------------------------------------------------------
1 | import toCamelCase from '../src/tocamelcase'
2 |
3 | describe('strman.toCamelCase', () => {
4 | test('should match camelCase', () => {
5 | const fixtures = ['CamelCase', 'camelCase', 'Camel case', 'Camel case', 'camel Case', 'camel-case', '-camel--case', 'camel_case', ' camel_case']
6 |
7 | fixtures.forEach((el) => {
8 | expect(toCamelCase(el)).toBe('camelCase')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/tokebabcase.strman.test.js:
--------------------------------------------------------------------------------
1 | import { toKebabCase } from '../src/strman'
2 |
3 | describe('strman.toKebabCase', () => {
4 | test('should match de_camelize', () => {
5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize']
6 |
7 | fixtures.forEach((el) => {
8 | expect(toKebabCase(el)).toBe('de-camelize')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/tokebabcase.test.js:
--------------------------------------------------------------------------------
1 | import toKebabCase from '../src/tokebabcase'
2 |
3 | describe('strman.toKebabCase', () => {
4 | test('should match de_camelize', () => {
5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize']
6 |
7 | fixtures.forEach((el) => {
8 | expect(toKebabCase(el)).toBe('de-camelize')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/tosnakecase.strman.test.js:
--------------------------------------------------------------------------------
1 | import { toSnakeCase } from '../src/strman'
2 |
3 | describe('strman.toSnakeCase', () => {
4 | test('should match de_camelize', () => {
5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize']
6 |
7 | fixtures.forEach((el) => {
8 | expect(toSnakeCase(el)).toBe('de_camelize')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/tosnakecase.test.js:
--------------------------------------------------------------------------------
1 | import toSnakeCase from '../src/tosnakecase'
2 |
3 | describe('strman.toSnakeCase', () => {
4 | test('should match de_camelize', () => {
5 | const fixtures = ['deCamelize', 'de-Camelize', 'de camelize', 'de camelize', 'de Camelize', 'de-camelize', '-de--camelize', 'de_camelize', ' de_camelize']
6 |
7 | fixtures.forEach((el) => {
8 | expect(toSnakeCase(el)).toBe('de_camelize')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/tostudlycaps.strman.test.js:
--------------------------------------------------------------------------------
1 | import { toStudlyCaps } from '../src/strman'
2 |
3 | describe('strman.toStudlyCaps', () => {
4 | test('should match DeCamelize', () => {
5 | const fixtures = [
6 | 'deCamelize',
7 | 'de-Camelize',
8 | 'de camelize',
9 | 'de camelize',
10 | 'de Camelize',
11 | 'de-camelize',
12 | '-de--camelize',
13 | 'de_camelize',
14 | ' de_camelize',
15 | ]
16 |
17 | fixtures.forEach((el) => {
18 | expect(toStudlyCaps(el)).toBe('DeCamelize')
19 | })
20 | })
21 | test('should match DeCamelize', () => {
22 | const fixtures = [
23 | `
24 | 1`,
25 | ]
26 |
27 | fixtures.forEach((el) => {
28 | expect(toStudlyCaps(el)).toBe('1')
29 | })
30 | })
31 | })
32 |
--------------------------------------------------------------------------------
/test/tostudlycaps.test.js:
--------------------------------------------------------------------------------
1 | import toStudlyCaps from '../src/tostudlycaps'
2 |
3 | describe('strman.toStudlyCaps', () => {
4 | test('should match DeCamelize', () => {
5 | const fixtures = [
6 | 'deCamelize',
7 | 'de-Camelize',
8 | 'de camelize',
9 | 'de camelize',
10 | 'de Camelize',
11 | 'de-camelize',
12 | '-de--camelize',
13 | 'de_camelize',
14 | ' de_camelize',
15 | ]
16 |
17 | fixtures.forEach((el) => {
18 | expect(toStudlyCaps(el)).toBe('DeCamelize')
19 | })
20 | })
21 | test('should match DeCamelize', () => {
22 | const fixtures = [
23 | `
24 | 1`,
25 | ]
26 |
27 | fixtures.forEach((el) => {
28 | expect(toStudlyCaps(el)).toBe('1')
29 | })
30 | })
31 | })
32 |
--------------------------------------------------------------------------------
/test/transliterate.strman.test.js:
--------------------------------------------------------------------------------
1 | import { transliterate } from '../src/strman'
2 |
3 | describe('strman.transliterate', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['fóõ bár']
6 |
7 | fixtures.forEach((el) => {
8 | expect(transliterate(el)).toBe('foo bar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/transliterate.test.js:
--------------------------------------------------------------------------------
1 | import transliterate from '../src/transliterate'
2 |
3 | describe('strman.transliterate', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['fóõ bár']
6 |
7 | fixtures.forEach((el) => {
8 | expect(transliterate(el)).toBe('foo bar')
9 | })
10 | })
11 | })
12 |
--------------------------------------------------------------------------------
/test/trim.strman.test.js:
--------------------------------------------------------------------------------
1 | import { trim } from '../src/strman'
2 |
3 | describe('strman.trim', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(trim(el)).toBe('foo bar')
9 | })
10 | })
11 |
12 | test('should be foo bar without @', () => {
13 | const fixtures = ['foo bar', 'foo bar@', '@foo bar', '@@foo bar@@@']
14 |
15 | fixtures.forEach((el) => {
16 | expect(trim(el, '@')).toBe('foo bar')
17 | })
18 | })
19 |
20 | test('should be foo bar without @ and with #', () => {
21 | const fixtures = ['@#foo bar', '#foo bar@', '@#foo bar@', '@@#foo bar@@@']
22 |
23 | fixtures.forEach((el) => {
24 | expect(trim(el, '@')).toBe('#foo bar')
25 | })
26 | })
27 | })
28 |
--------------------------------------------------------------------------------
/test/trim.test.js:
--------------------------------------------------------------------------------
1 | import trim from '../src/trim'
2 |
3 | describe('strman.trim', () => {
4 | test('should be foo bar', () => {
5 | const fixtures = ['foo bar', 'foo bar ', ' foo bar', ' foo bar ']
6 |
7 | fixtures.forEach((el) => {
8 | expect(trim(el)).toBe('foo bar')
9 | })
10 | })
11 |
12 | test('should be foo bar without @', () => {
13 | const fixtures = ['foo bar', 'foo bar@', '@foo bar', '@@foo bar@@@']
14 |
15 | fixtures.forEach((el) => {
16 | expect(trim(el, '@')).toBe('foo bar')
17 | })
18 | })
19 |
20 | test('should be foo bar without @ and with #', () => {
21 | const fixtures = ['@#foo bar', '#foo bar@', '@#foo bar@', '@@#foo bar@@@']
22 |
23 | fixtures.forEach((el) => {
24 | expect(trim(el, '@')).toBe('#foo bar')
25 | })
26 | })
27 | })
28 |
--------------------------------------------------------------------------------
/test/truncate.strman.test.js:
--------------------------------------------------------------------------------
1 | import { truncate } from '../src/strman'
2 |
3 | describe('strman.truncate', () => {
4 | test('should be strings truncated', () => {
5 | expect(truncate('foo bar', 0, '.')).toBe('')
6 | expect(truncate('foo bar', 3, '.')).toBe('fo.')
7 | expect(truncate('foo bar', 2, '.')).toBe('f.')
8 | expect(truncate('foo bar', 4, '.')).toBe('foo.')
9 | expect(truncate('foo bar', 7, '.')).toBe('foo bar')
10 | expect(truncate('foo bar', 8, '.')).toBe('foo bar')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/truncate.test.js:
--------------------------------------------------------------------------------
1 | import truncate from '../src/truncate'
2 |
3 | describe('strman.truncate', () => {
4 | test('should be strings truncated', () => {
5 | expect(truncate('foo bar', 0, '.')).toBe('')
6 | expect(truncate('foo bar', 3, '.')).toBe('fo.')
7 | expect(truncate('foo bar', 2, '.')).toBe('f.')
8 | expect(truncate('foo bar', 4, '.')).toBe('foo.')
9 | expect(truncate('foo bar', 7, '.')).toBe('foo bar')
10 | expect(truncate('foo bar', 8, '.')).toBe('foo bar')
11 | })
12 | })
13 |
--------------------------------------------------------------------------------
/test/urldecode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { urlDecode } from '../src/strman'
2 |
3 | describe('strman.slice', () => {
4 | test('should be foobar', () => {
5 | expect(urlDecode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/')
6 | expect(urlDecode('https://web.whatsapp.com/?text=%20a')).toBe('https://web.whatsapp.com/?text= a')
7 | expect(urlDecode('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')).toBe('https://web.whatsapp.com/?text=áéíóú')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/urldecode.test.js:
--------------------------------------------------------------------------------
1 | import urlDecode from '../src/urlDecode'
2 |
3 | describe('strman.slice', () => {
4 | test('should be foobar', () => {
5 | expect(urlDecode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/')
6 | expect(urlDecode('https://web.whatsapp.com/?text=%20a')).toBe('https://web.whatsapp.com/?text= a')
7 | expect(urlDecode('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')).toBe('https://web.whatsapp.com/?text=áéíóú')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/urlencode.strman.test.js:
--------------------------------------------------------------------------------
1 | import { urlEncode } from '../src/strman'
2 |
3 | describe('strman.slice', () => {
4 | test('should be foobar', () => {
5 | expect(urlEncode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/')
6 | expect(urlEncode('https://web.whatsapp.com/?text=áéíóú')).toBe('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')
7 | expect(urlEncode('https://web.whatsapp.com/?text= a')).toBe('https://web.whatsapp.com/?text=%20a')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------
/test/urlencode.test.js:
--------------------------------------------------------------------------------
1 | import urlEncode from '../src/urlencode'
2 |
3 | describe('strman.slice', () => {
4 | test('should be foobar', () => {
5 | expect(urlEncode('https://web.whatsapp.com/')).toBe('https://web.whatsapp.com/')
6 | expect(urlEncode('https://web.whatsapp.com/?text=áéíóú')).toBe('https://web.whatsapp.com/?text=%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA')
7 | expect(urlEncode('https://web.whatsapp.com/?text= a')).toBe('https://web.whatsapp.com/?text=%20a')
8 | })
9 | })
10 |
--------------------------------------------------------------------------------