@onivoro/isomorphic-common 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # isomorphic-common
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test isomorphic-common` to execute the unit tests via [Jest](https://jestjs.io).
8
+
9
+ ## Running lint
10
+
11
+ Run `nx lint isomorphic-common` to execute the lint via [ESLint](https://eslint.org/).
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@onivoro/isomorphic-common",
3
+ "version": "0.0.1",
4
+ "peerDependencies": {
5
+ "tslib": "^2.3.0"
6
+ },
7
+ "main": "./src/index.js",
8
+ "types": "./src/index.d.ts"
9
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib/strings/snake-case.function';
2
+ export * from './lib/strings/unicode-words.const';
3
+ export * from './lib/strings/words.function';
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/strings/snake-case.function"), exports);
5
+ tslib_1.__exportStar(require("./lib/strings/unicode-words.const"), exports);
6
+ tslib_1.__exportStar(require("./lib/strings/words.function"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/isomorphic-common/src/index.ts"],"names":[],"mappings":";;;AAAA,4EAAkD;AAClD,4EAAkD;AAClD,uEAA6C"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Converts `string` to
3
+ * [snake case](https://en.wikipedia.org/wiki/Snake_case).
4
+ *
5
+ * @since 3.0.0
6
+ * @category String
7
+ * @param {string} [string=''] The string to convert.
8
+ * @returns {string} Returns the snake cased string.
9
+ * @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst
10
+ * @example
11
+ *
12
+ * snakeCase('Foo Bar')
13
+ * // => 'foo_bar'
14
+ *
15
+ * snakeCase('fooBar')
16
+ * // => 'foo_bar'
17
+ *
18
+ * snakeCase('--FOO-BAR--')
19
+ * // => 'foo_bar'
20
+ *
21
+ * snakeCase('foo2bar')
22
+ * // => 'foo_2_bar'
23
+ */
24
+ export declare function snakeCase(string: any): any;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // source https://github.com/lodash/lodash/blob/master/snakeCase.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.snakeCase = void 0;
5
+ const words_function_1 = require("./words.function");
6
+ /**
7
+ * Converts `string` to
8
+ * [snake case](https://en.wikipedia.org/wiki/Snake_case).
9
+ *
10
+ * @since 3.0.0
11
+ * @category String
12
+ * @param {string} [string=''] The string to convert.
13
+ * @returns {string} Returns the snake cased string.
14
+ * @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst
15
+ * @example
16
+ *
17
+ * snakeCase('Foo Bar')
18
+ * // => 'foo_bar'
19
+ *
20
+ * snakeCase('fooBar')
21
+ * // => 'foo_bar'
22
+ *
23
+ * snakeCase('--FOO-BAR--')
24
+ * // => 'foo_bar'
25
+ *
26
+ * snakeCase('foo2bar')
27
+ * // => 'foo_2_bar'
28
+ */
29
+ function snakeCase(string) {
30
+ return ((0, words_function_1.words)(string.replace(/['\u2019]/g, '')).reduce((result, word, index) => (result + (index ? '_' : '') + word.toLowerCase()), ''));
31
+ }
32
+ exports.snakeCase = snakeCase;
33
+ //# sourceMappingURL=snake-case.function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snake-case.function.js","sourceRoot":"","sources":["../../../../../../libs/isomorphic-common/src/lib/strings/snake-case.function.ts"],"names":[],"mappings":";AAAA,mEAAmE;;;AAEnE,qDAAyC;AAEzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,SAAS,CAAC,MAAM;IAC9B,OAAO,CACL,IAAA,sBAAK,EAAC,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CACtE,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CACjD,EAAE,EAAE,CAAC,CACP,CAAC;AACJ,CAAC;AAND,8BAMC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Splits a Unicode `string` into an array of its words.
3
+ *
4
+ * @private
5
+ * @param {string} The string to inspect.
6
+ * @returns {Array} Returns the words of `string`.
7
+ */
8
+ export declare function unicodeWords(string: any): any;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ // source https://github.com/lodash/lodash/blob/master/.internal/unicodeWords.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.unicodeWords = void 0;
5
+ /** Used to compose unicode character classes. */
6
+ const rsAstralRange = '\\ud800-\\udfff';
7
+ const rsComboMarksRange = '\\u0300-\\u036f';
8
+ const reComboHalfMarksRange = '\\ufe20-\\ufe2f';
9
+ const rsComboSymbolsRange = '\\u20d0-\\u20ff';
10
+ const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff';
11
+ const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff';
12
+ const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange;
13
+ const rsDingbatRange = '\\u2700-\\u27bf';
14
+ const rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff';
15
+ const rsMathOpRange = '\\xac\\xb1\\xd7\\xf7';
16
+ const rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
17
+ const rsPunctuationRange = '\\u2000-\\u206f';
18
+ const rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000';
19
+ const rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
20
+ const rsVarRange = '\\ufe0e\\ufe0f';
21
+ const rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
22
+ /** Used to compose unicode capture groups. */
23
+ const rsApos = "['\u2019]";
24
+ const rsBreak = `[${rsBreakRange}]`;
25
+ const rsCombo = `[${rsComboRange}]`;
26
+ const rsDigit = '\\d';
27
+ const rsDingbat = `[${rsDingbatRange}]`;
28
+ const rsLower = `[${rsLowerRange}]`;
29
+ const rsMisc = `[^${rsAstralRange}${rsBreakRange + rsDigit + rsDingbatRange + rsLowerRange + rsUpperRange}]`;
30
+ const rsFitz = '\\ud83c[\\udffb-\\udfff]';
31
+ const rsModifier = `(?:${rsCombo}|${rsFitz})`;
32
+ const rsNonAstral = `[^${rsAstralRange}]`;
33
+ const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
34
+ const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
35
+ const rsUpper = `[${rsUpperRange}]`;
36
+ const rsZWJ = '\\u200d';
37
+ /** Used to compose unicode regexes. */
38
+ const rsMiscLower = `(?:${rsLower}|${rsMisc})`;
39
+ const rsMiscUpper = `(?:${rsUpper}|${rsMisc})`;
40
+ const rsOptContrLower = `(?:${rsApos}(?:d|ll|m|re|s|t|ve))?`;
41
+ const rsOptContrUpper = `(?:${rsApos}(?:D|LL|M|RE|S|T|VE))?`;
42
+ const reOptMod = `${rsModifier}?`;
43
+ const rsOptVar = `[${rsVarRange}]?`;
44
+ const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`;
45
+ const rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
46
+ const rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
47
+ const rsSeq = rsOptVar + reOptMod + rsOptJoin;
48
+ const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}`;
49
+ const reUnicodeWords = RegExp([
50
+ `${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`,
51
+ `${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`,
52
+ `${rsUpper}?${rsMiscLower}+${rsOptContrLower}`,
53
+ `${rsUpper}+${rsOptContrUpper}`,
54
+ rsOrdUpper,
55
+ rsOrdLower,
56
+ `${rsDigit}+`,
57
+ rsEmoji
58
+ ].join('|'), 'g');
59
+ /**
60
+ * Splits a Unicode `string` into an array of its words.
61
+ *
62
+ * @private
63
+ * @param {string} The string to inspect.
64
+ * @returns {Array} Returns the words of `string`.
65
+ */
66
+ function unicodeWords(string) {
67
+ return string.match(reUnicodeWords);
68
+ }
69
+ exports.unicodeWords = unicodeWords;
70
+ //# sourceMappingURL=unicode-words.const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unicode-words.const.js","sourceRoot":"","sources":["../../../../../../libs/isomorphic-common/src/lib/strings/unicode-words.const.ts"],"names":[],"mappings":";AAAA,gFAAgF;;;AAEhF,iDAAiD;AACjD,MAAM,aAAa,GAAG,iBAAiB,CAAA;AACvC,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAC3C,MAAM,qBAAqB,GAAG,iBAAiB,CAAA;AAC/C,MAAM,mBAAmB,GAAG,iBAAiB,CAAA;AAC7C,MAAM,yBAAyB,GAAG,iBAAiB,CAAA;AACnD,MAAM,2BAA2B,GAAG,iBAAiB,CAAA;AACrD,MAAM,YAAY,GAAG,iBAAiB,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,yBAAyB,GAAG,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ACrC,CAAC;AAFD,oCAEC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Splits `string` into an array of its words.
3
+ *
4
+ * @since 3.0.0
5
+ * @category String
6
+ * @param {string} [string=''] The string to inspect.
7
+ * @param {RegExp|string} [pattern] The pattern to match words.
8
+ * @returns {Array} Returns the words of `string`.
9
+ * @example
10
+ *
11
+ * words('fred, barney, & pebbles')
12
+ * // => ['fred', 'barney', 'pebbles']
13
+ *
14
+ * words('fred, barney, & pebbles', /[^, ]+/g)
15
+ * // => ['fred', 'barney', '&', 'pebbles']
16
+ */
17
+ export declare function words(string: string, pattern?: RegExp): any;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ // source https://github.com/lodash/lodash/blob/master/words.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.words = void 0;
5
+ const unicode_words_const_1 = require("./unicode-words.const");
6
+ const hasUnicodeWord = RegExp.prototype.test.bind(/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/);
7
+ /** Used to match words composed of alphanumeric characters. */
8
+ const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
9
+ function asciiWords(string) {
10
+ return string.match(reAsciiWord);
11
+ }
12
+ /**
13
+ * Splits `string` into an array of its words.
14
+ *
15
+ * @since 3.0.0
16
+ * @category String
17
+ * @param {string} [string=''] The string to inspect.
18
+ * @param {RegExp|string} [pattern] The pattern to match words.
19
+ * @returns {Array} Returns the words of `string`.
20
+ * @example
21
+ *
22
+ * words('fred, barney, & pebbles')
23
+ * // => ['fred', 'barney', 'pebbles']
24
+ *
25
+ * words('fred, barney, & pebbles', /[^, ]+/g)
26
+ * // => ['fred', 'barney', '&', 'pebbles']
27
+ */
28
+ function words(string, pattern) {
29
+ if (pattern === undefined) {
30
+ const result = hasUnicodeWord(string) ? (0, unicode_words_const_1.unicodeWords)(string) : asciiWords(string);
31
+ return result || [];
32
+ }
33
+ return string.match(pattern) || [];
34
+ }
35
+ exports.words = words;
36
+ //# sourceMappingURL=words.function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"words.function.js","sourceRoot":"","sources":["../../../../../../libs/isomorphic-common/src/lib/strings/words.function.ts"],"names":[],"mappings":";AAAA,+DAA+D;;;AAE/D,+DAAqD;AAErD,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAC/C,oEAAoE,CACrE,CAAA;AAED,+DAA+D;AAC/D,MAAM,WAAW,GAAG,2CAA2C,CAAA;AAE/D,SAAS,UAAU,CAAC,MAAM;IACxB,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,KAAK,CAAC,MAAc,EAAE,OAAgB;IACpD,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAA,kCAAY,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;QACjF,OAAO,MAAM,IAAI,EAAE,CAAA;KACpB;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;AACpC,CAAC;AAND,sBAMC"}