@selfcommunity/utils 0.1.2-alpha.0
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/LICENSE.md +21 -0
- package/README.md +12 -0
- package/lib/cjs/index.d.js +2 -0
- package/lib/cjs/index.js +17 -0
- package/lib/cjs/utils/string.js +57 -0
- package/lib/cjs/utils/url.js +70 -0
- package/lib/esm/index.d.js +2 -0
- package/lib/esm/index.d.ts +7 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +17 -0
- package/lib/esm/utils/string.d.ts +21 -0
- package/lib/esm/utils/string.d.ts.map +1 -0
- package/lib/esm/utils/string.js +57 -0
- package/lib/esm/utils/url.d.ts +22 -0
- package/lib/esm/utils/url.d.ts.map +1 -0
- package/lib/esm/utils/url.js +70 -0
- package/lib/umd/utils.js +3 -0
- package/lib/umd/utils.js.LICENSE.txt +1 -0
- package/lib/umd/utils.js.map +1 -0
- package/package.json +105 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Quentral Srl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@selfcommunity/utils
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
[](https://github.com/selfcommunity/community-js/blob/master/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/@selfcommunity/utils)
|
|
6
|
+
[](https://www.npmjs.com/package/@selfcommunity/utils)
|
|
7
|
+
[](https://twitter.com/community_self)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Install
|
|
11
|
+
|
|
12
|
+
`npm install @selfcommunity/utils`
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
|
|
5
|
+
var _string = require("./utils/string");
|
|
6
|
+
|
|
7
|
+
exports.capitalize = _string.capitalize;
|
|
8
|
+
exports.isString = _string.isString;
|
|
9
|
+
exports.stripHtml = _string.stripHtml;
|
|
10
|
+
exports.camelCase = _string.camelCase;
|
|
11
|
+
|
|
12
|
+
var _url = require("./utils/url");
|
|
13
|
+
|
|
14
|
+
exports.isValidUrl = _url.isValidUrl;
|
|
15
|
+
exports.isValidUrls = _url.isValidUrls;
|
|
16
|
+
exports.urlReplacer = _url.urlReplacer;
|
|
17
|
+
exports.getDomain = _url.getDomain;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.camelCase = camelCase;
|
|
5
|
+
exports.capitalize = capitalize;
|
|
6
|
+
exports.isString = isString;
|
|
7
|
+
exports.stripHtml = stripHtml;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if v is a string
|
|
11
|
+
* @param v
|
|
12
|
+
*/
|
|
13
|
+
function isString(v) {
|
|
14
|
+
return typeof v === 'string' || v instanceof String;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Capitalize a string
|
|
18
|
+
* @param str
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function capitalize(str) {
|
|
23
|
+
let strVal = '';
|
|
24
|
+
let strArr = str.split(' ');
|
|
25
|
+
|
|
26
|
+
for (let chr = 0; chr < strArr.length; chr++) {
|
|
27
|
+
strVal += strArr[chr].substring(0, 1).toUpperCase() + strArr[chr].substring(1, strArr[chr].length);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return strVal;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* CamelCase a string
|
|
34
|
+
* @param str
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function camelCase(str) {
|
|
39
|
+
// Lower cases the string
|
|
40
|
+
return str.toLowerCase() // Replaces any - or _ characters with a space
|
|
41
|
+
.replace(/[-_]+/g, ' ') // Removes any non alphanumeric characters
|
|
42
|
+
.replace(/[^\w\s]/g, '') // Uppercases the first character in each group immediately following a space
|
|
43
|
+
// (delimited by spaces)
|
|
44
|
+
.replace(/ (.)/g, $1 => {
|
|
45
|
+
return $1.toUpperCase();
|
|
46
|
+
}) // Removes spaces
|
|
47
|
+
.replace(/ /g, '');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Stripe html tags from a string
|
|
51
|
+
* @param str
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function stripHtml(str) {
|
|
56
|
+
return str.replace(/<[^>]*>?/gm, '').trim();
|
|
57
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Utility Url Replacer
|
|
8
|
+
* @param path
|
|
9
|
+
*/
|
|
10
|
+
const urlReplacer = path => {
|
|
11
|
+
const replacer = function replacer(tpl, data) {
|
|
12
|
+
const re = /\$\(([^)]+)?\)/g;
|
|
13
|
+
let match = re.exec(tpl);
|
|
14
|
+
|
|
15
|
+
while (match) {
|
|
16
|
+
tpl = tpl.replace(match[0], data[match[1]]);
|
|
17
|
+
re.lastIndex = 0;
|
|
18
|
+
match = re.exec(tpl);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return tpl;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return params => replacer(path, params);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get domain
|
|
28
|
+
* @param url
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.urlReplacer = urlReplacer;
|
|
33
|
+
|
|
34
|
+
const getDomain = url => {
|
|
35
|
+
// eslint-disable-next-line no-useless-escape,@typescript-eslint/prefer-regexp-exec
|
|
36
|
+
const matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
|
|
37
|
+
|
|
38
|
+
if (matches && matches[1]) {
|
|
39
|
+
return matches[1];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return '';
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Check a str is a valid url pattern
|
|
46
|
+
* @param url
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
exports.getDomain = getDomain;
|
|
51
|
+
|
|
52
|
+
const isValidUrl = url => {
|
|
53
|
+
const regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
|
|
54
|
+
return regexp.test(url);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Check a str is a valid list of urls separated by delimiter
|
|
58
|
+
* @param value
|
|
59
|
+
* @param delimiter
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.isValidUrl = isValidUrl;
|
|
64
|
+
|
|
65
|
+
const isValidUrls = (value, delimiter) => {
|
|
66
|
+
const urls = value.trim().split(delimiter);
|
|
67
|
+
return urls.every(isValidUrl);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.isValidUrls = isValidUrls;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { capitalize, isString, stripHtml, camelCase } from './utils/string';
|
|
2
|
+
import { isValidUrl, isValidUrls, urlReplacer, getDomain } from './utils/url';
|
|
3
|
+
/**
|
|
4
|
+
* Export all utilities
|
|
5
|
+
*/
|
|
6
|
+
export { capitalize, isString, stripHtml, camelCase, isValidUrl, isValidUrls, urlReplacer, getDomain };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAC,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAE5E;;GAEG;AACH,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAC,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
|
|
5
|
+
var _string = require("./utils/string");
|
|
6
|
+
|
|
7
|
+
exports.capitalize = _string.capitalize;
|
|
8
|
+
exports.isString = _string.isString;
|
|
9
|
+
exports.stripHtml = _string.stripHtml;
|
|
10
|
+
exports.camelCase = _string.camelCase;
|
|
11
|
+
|
|
12
|
+
var _url = require("./utils/url");
|
|
13
|
+
|
|
14
|
+
exports.isValidUrl = _url.isValidUrl;
|
|
15
|
+
exports.isValidUrls = _url.isValidUrls;
|
|
16
|
+
exports.urlReplacer = _url.urlReplacer;
|
|
17
|
+
exports.getDomain = _url.getDomain;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if v is a string
|
|
3
|
+
* @param v
|
|
4
|
+
*/
|
|
5
|
+
export declare function isString(v: any): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Capitalize a string
|
|
8
|
+
* @param str
|
|
9
|
+
*/
|
|
10
|
+
export declare function capitalize(str: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* CamelCase a string
|
|
13
|
+
* @param str
|
|
14
|
+
*/
|
|
15
|
+
export declare function camelCase(str: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Stripe html tags from a string
|
|
18
|
+
* @param str
|
|
19
|
+
*/
|
|
20
|
+
export declare function stripHtml(str: string): string;
|
|
21
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/utils/string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,KAAA,WAEzB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB7C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.camelCase = camelCase;
|
|
5
|
+
exports.capitalize = capitalize;
|
|
6
|
+
exports.isString = isString;
|
|
7
|
+
exports.stripHtml = stripHtml;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if v is a string
|
|
11
|
+
* @param v
|
|
12
|
+
*/
|
|
13
|
+
function isString(v) {
|
|
14
|
+
return typeof v === 'string' || v instanceof String;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Capitalize a string
|
|
18
|
+
* @param str
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function capitalize(str) {
|
|
23
|
+
let strVal = '';
|
|
24
|
+
let strArr = str.split(' ');
|
|
25
|
+
|
|
26
|
+
for (let chr = 0; chr < strArr.length; chr++) {
|
|
27
|
+
strVal += strArr[chr].substring(0, 1).toUpperCase() + strArr[chr].substring(1, strArr[chr].length);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return strVal;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* CamelCase a string
|
|
34
|
+
* @param str
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function camelCase(str) {
|
|
39
|
+
// Lower cases the string
|
|
40
|
+
return str.toLowerCase() // Replaces any - or _ characters with a space
|
|
41
|
+
.replace(/[-_]+/g, ' ') // Removes any non alphanumeric characters
|
|
42
|
+
.replace(/[^\w\s]/g, '') // Uppercases the first character in each group immediately following a space
|
|
43
|
+
// (delimited by spaces)
|
|
44
|
+
.replace(/ (.)/g, $1 => {
|
|
45
|
+
return $1.toUpperCase();
|
|
46
|
+
}) // Removes spaces
|
|
47
|
+
.replace(/ /g, '');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Stripe html tags from a string
|
|
51
|
+
* @param str
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function stripHtml(str) {
|
|
56
|
+
return str.replace(/<[^>]*>?/gm, '').trim();
|
|
57
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Url Replacer
|
|
3
|
+
* @param path
|
|
4
|
+
*/
|
|
5
|
+
export declare const urlReplacer: (path: string) => (params: object) => any;
|
|
6
|
+
/**
|
|
7
|
+
* Get domain
|
|
8
|
+
* @param url
|
|
9
|
+
*/
|
|
10
|
+
export declare const getDomain: (url: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Check a str is a valid url pattern
|
|
13
|
+
* @param url
|
|
14
|
+
*/
|
|
15
|
+
export declare const isValidUrl: (url: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Check a str is a valid list of urls separated by delimiter
|
|
18
|
+
* @param value
|
|
19
|
+
* @param delimiter
|
|
20
|
+
*/
|
|
21
|
+
export declare const isValidUrls: (value: string, delimiter: string) => boolean;
|
|
22
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,cAWtB,MAAM,QACvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,MAOvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,OAGxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,UAAW,MAAM,aAAa,MAAM,KAAG,OAG9D,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.urlReplacer = exports.isValidUrls = exports.isValidUrl = exports.getDomain = void 0;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Utility Url Replacer
|
|
8
|
+
* @param path
|
|
9
|
+
*/
|
|
10
|
+
const urlReplacer = path => {
|
|
11
|
+
const replacer = function replacer(tpl, data) {
|
|
12
|
+
const re = /\$\(([^)]+)?\)/g;
|
|
13
|
+
let match = re.exec(tpl);
|
|
14
|
+
|
|
15
|
+
while (match) {
|
|
16
|
+
tpl = tpl.replace(match[0], data[match[1]]);
|
|
17
|
+
re.lastIndex = 0;
|
|
18
|
+
match = re.exec(tpl);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return tpl;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return params => replacer(path, params);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get domain
|
|
28
|
+
* @param url
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.urlReplacer = urlReplacer;
|
|
33
|
+
|
|
34
|
+
const getDomain = url => {
|
|
35
|
+
// eslint-disable-next-line no-useless-escape,@typescript-eslint/prefer-regexp-exec
|
|
36
|
+
const matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
|
|
37
|
+
|
|
38
|
+
if (matches && matches[1]) {
|
|
39
|
+
return matches[1];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return '';
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Check a str is a valid url pattern
|
|
46
|
+
* @param url
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
exports.getDomain = getDomain;
|
|
51
|
+
|
|
52
|
+
const isValidUrl = url => {
|
|
53
|
+
const regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/;
|
|
54
|
+
return regexp.test(url);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Check a str is a valid list of urls separated by delimiter
|
|
58
|
+
* @param value
|
|
59
|
+
* @param delimiter
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.isValidUrl = isValidUrl;
|
|
64
|
+
|
|
65
|
+
const isValidUrls = (value, delimiter) => {
|
|
66
|
+
const urls = value.trim().split(delimiter);
|
|
67
|
+
return urls.every(isValidUrl);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.isValidUrls = isValidUrls;
|
package/lib/umd/utils.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! For license information please see utils.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SelfCommunityUtils=t():e.SelfCommunityUtils=t()}(self,(()=>(()=>{"use strict";var e={884:(e,t)=>{t.__esModule=!0,t.camelCase=function(e){return e.toLowerCase().replace(/[-_]+/g," ").replace(/[^\w\s]/g,"").replace(/ (.)/g,(e=>e.toUpperCase())).replace(/ /g,"")},t.capitalize=function(e){let t="",r=e.split(" ");for(let e=0;e<r.length;e++)t+=r[e].substring(0,1).toUpperCase()+r[e].substring(1,r[e].length);return t},t.isString=function(e){return"string"==typeof e||e instanceof String},t.stripHtml=function(e){return e.replace(/<[^>]*>?/gm,"").trim()}},735:(e,t)=>{t.__esModule=!0,t.urlReplacer=t.isValidUrls=t.isValidUrl=t.getDomain=void 0,t.urlReplacer=e=>t=>function(e,t){const r=/\$\(([^)]+)?\)/g;let i=r.exec(e);for(;i;)e=e.replace(i[0],t[i[1]]),r.lastIndex=0,i=r.exec(e);return e}(e,t),t.getDomain=e=>{const t=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);return t&&t[1]?t[1]:""};const r=e=>/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e);t.isValidUrl=r,t.isValidUrls=(e,t)=>e.trim().split(t).every(r)}},t={};function r(i){var l=t[i];if(void 0!==l)return l.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,r),s.exports}var i={};return(()=>{var e=i;e.__esModule=!0;var t=r(884);e.capitalize=t.capitalize,e.isString=t.isString,e.stripHtml=t.stripHtml,e.camelCase=t.camelCase;var l=r(735);e.isValidUrl=l.isValidUrl,e.isValidUrls=l.isValidUrls,e.urlReplacer=l.urlReplacer,e.getDomain=l.getDomain})(),i})()));
|
|
3
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! (c) 2022 - present: Quentral Srl | https://github.com/selfcommunity/community-js/blob/master/LICENSE.md */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAA4B,mBAAID,IAEhCD,EAAyB,mBAAIC,IAR/B,CASGK,MAAM,IACT,kECeO,SAAmBC,GAExB,OACEA,EACGC,cAEAC,QAAQ,SAAU,KAElBA,QAAQ,WAAY,IAGpBA,QAAQ,SAAUC,GACVA,EAAGC,gBAGXF,QAAQ,KAAM,kBA5Bd,SAAoBF,GACzB,IAAIK,EAAS,GACTC,EAAmBN,EAAIO,MAAM,KACjC,IAAK,IAAIC,EAAM,EAAGA,EAAMF,EAAOG,OAAQD,IACrCH,GAAUC,EAAOE,GAAKE,UAAU,EAAG,GAAGN,cAAgBE,EAAOE,GAAKE,UAAU,EAAGJ,EAAOE,GAAKC,QAE7F,OAAOJ,cAdF,SAAkBM,GACvB,MAAoB,iBAANA,GAAkBA,aAAaC,oBA2CxC,SAAmBZ,GACxB,OAAOA,EAAIE,QAAQ,aAAc,IAAIW,+GC7CXC,GAWlBC,GAVS,SAAUC,EAAKC,GAC9B,MAAMC,EAAK,kBACX,IAAIC,EAAQD,EAAGE,KAAKJ,GACpB,KAAOG,GACLH,EAAMA,EAAId,QAAQiB,EAAM,GAAIF,EAAKE,EAAM,KACvCD,EAAGG,UAAY,EACfF,EAAQD,EAAGE,KAAKJ,GAElB,OAAOA,EAEkBM,CAASR,EAAMC,eAOlBQ,IAExB,MAAMC,EAAUD,EAAIJ,MAAM,wCAC1B,OAAIK,GAAWA,EAAQ,GACdA,EAAQ,GAEV,IAOF,MAAMC,EAAcF,GACV,mFACDG,KAAKH,gCAQM,CAACI,EAAeC,IAC5BD,EAAMd,OAAON,MAAMqB,GACpBC,MAAMJ,KC9ChBK,EAA2B,GAG/B,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAatC,QAGrB,IAAIC,EAASkC,EAAyBE,GAAY,CAGjDrC,QAAS,IAOV,OAHAwC,EAAoBH,GAAUpC,EAAQA,EAAOD,QAASoC,GAG/CnC,EAAOD,qDCrBf,6GACA,8HJSA","sources":["webpack://SelfCommunityUtils/webpack/universalModuleDefinition","webpack://SelfCommunityUtils/./src/utils/string.ts","webpack://SelfCommunityUtils/./src/utils/url.ts","webpack://SelfCommunityUtils/webpack/bootstrap","webpack://SelfCommunityUtils/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SelfCommunityUtils\"] = factory();\n\telse\n\t\troot[\"SelfCommunityUtils\"] = factory();\n})(self, () => {\nreturn ","/**\n * Check if v is a string\n * @param v\n */\nexport function isString(v) {\n return typeof v === 'string' || v instanceof String;\n}\n\n/**\n * Capitalize a string\n * @param str\n */\nexport function capitalize(str: string): string {\n let strVal = '';\n let strArr: string[] = str.split(' ');\n for (let chr = 0; chr < strArr.length; chr++) {\n strVal += strArr[chr].substring(0, 1).toUpperCase() + strArr[chr].substring(1, strArr[chr].length);\n }\n return strVal;\n}\n\n/**\n * CamelCase a string\n * @param str\n */\nexport function camelCase(str: string): string {\n // Lower cases the string\n return (\n str\n .toLowerCase()\n // Replaces any - or _ characters with a space\n .replace(/[-_]+/g, ' ')\n // Removes any non alphanumeric characters\n .replace(/[^\\w\\s]/g, '')\n // Uppercases the first character in each group immediately following a space\n // (delimited by spaces)\n .replace(/ (.)/g, ($1) => {\n return $1.toUpperCase();\n })\n // Removes spaces\n .replace(/ /g, '')\n );\n}\n\n/**\n * Stripe html tags from a string\n * @param str\n */\nexport function stripHtml(str: string): string {\n return str.replace(/<[^>]*>?/gm, '').trim();\n}\n","/**\n * Utility Url Replacer\n * @param path\n */\nexport const urlReplacer = (path: string) => {\n const replacer = function (tpl, data) {\n const re = /\\$\\(([^)]+)?\\)/g;\n let match = re.exec(tpl);\n while (match) {\n tpl = tpl.replace(match[0], data[match[1]]);\n re.lastIndex = 0;\n match = re.exec(tpl);\n }\n return tpl;\n };\n return (params: object) => replacer(path, params);\n};\n\n/**\n * Get domain\n * @param url\n */\nexport const getDomain = (url: string): string => {\n // eslint-disable-next-line no-useless-escape,@typescript-eslint/prefer-regexp-exec\n const matches = url.match(/^https?\\:\\/\\/([^\\/?#]+)(?:[\\/?#]|$)/i);\n if (matches && matches[1]) {\n return matches[1];\n }\n return '';\n};\n\n/**\n * Check a str is a valid url pattern\n * @param url\n */\nexport const isValidUrl = (url: string): boolean => {\n const regexp = /(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-/]))?/;\n return regexp.test(url);\n};\n\n/**\n * Check a str is a valid list of urls separated by delimiter\n * @param value\n * @param delimiter\n */\nexport const isValidUrls = (value: string, delimiter: string): boolean => {\n const urls = value.trim().split(delimiter);\n return urls.every(isValidUrl);\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","import {capitalize, isString, stripHtml, camelCase} from './utils/string';\nimport {isValidUrl, isValidUrls, urlReplacer, getDomain} from './utils/url';\n\n/**\n * Export all utilities\n */\nexport {capitalize, isString, stripHtml, camelCase, isValidUrl, isValidUrls, urlReplacer, getDomain};\n"],"names":["root","factory","exports","module","define","amd","self","str","toLowerCase","replace","$1","toUpperCase","strVal","strArr","split","chr","length","substring","v","String","trim","path","params","tpl","data","re","match","exec","lastIndex","replacer","url","matches","isValidUrl","test","value","delimiter","every","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@selfcommunity/utils",
|
|
3
|
+
"version": "0.1.2-alpha.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "./lib/cjs/index.js",
|
|
7
|
+
"module": "./lib/esm/index.js",
|
|
8
|
+
"description": "Utilities to integrate a Community.",
|
|
9
|
+
"author": "SelfCommunity <https://www.selfcommunity.com>",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"react",
|
|
12
|
+
"utils",
|
|
13
|
+
"community",
|
|
14
|
+
"selfcommunity",
|
|
15
|
+
"community-utils"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepare": "install-peers -f",
|
|
19
|
+
"install-peers": "install-peers -f",
|
|
20
|
+
"test": "npm run lint && npm run test-only",
|
|
21
|
+
"test-only": "jest --runInBand",
|
|
22
|
+
"tdd": "jest --watch --runInBand",
|
|
23
|
+
"lint": "eslint ./src test --ext .ts,.tsx,.js",
|
|
24
|
+
"prettier": "prettier './**/*.js' './**/*.css' './**/*.md' --write",
|
|
25
|
+
"prettier-list-different": "prettier './**/*.js' './**/*.css' './**/*.md' --list-different",
|
|
26
|
+
"clean:lib": "rimraf lib",
|
|
27
|
+
"clean:node_modules": "rimraf node_modules",
|
|
28
|
+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel --root-mode upward --extensions .js,.jsx,.ts,.tsx ./src --out-dir lib/cjs --ignore **/*.stories.js,**/*.spec.js --copy-files",
|
|
29
|
+
"build:es": "cross-env BABEL_ENV=es babel --root-mode upward --extensions .js,.jsx,.ts,.tsx ./src --out-dir lib/esm --ignore **/*.stories.js,**/*.spec.js --copy-files",
|
|
30
|
+
"build:umd": "webpack --mode production",
|
|
31
|
+
"build:types": "tsc -d --declarationDir lib/esm --declarationMap --resolveJsonModule --emitDeclarationOnly",
|
|
32
|
+
"build": "yarn clean:lib && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:types",
|
|
33
|
+
"prerelease": "yarn run clean:lib && yarn run build"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://www.selfcommunity.com",
|
|
36
|
+
"files": [
|
|
37
|
+
"lib"
|
|
38
|
+
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/selfcommunity/community-js/tree/main/packages/utils"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@babel/cli": "^7.12.13",
|
|
48
|
+
"@babel/core": "^7.12.13",
|
|
49
|
+
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
|
50
|
+
"@babel/plugin-proposal-export-default-from": "^7.12.13",
|
|
51
|
+
"@babel/plugin-proposal-export-namespace-from": "^7.12.13",
|
|
52
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
|
|
53
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.12.13",
|
|
54
|
+
"@babel/plugin-transform-modules-commonjs": "^7.12.13",
|
|
55
|
+
"@babel/preset-modules": "^0.1.4",
|
|
56
|
+
"@babel/preset-react": "^7.12.13",
|
|
57
|
+
"@babel/preset-typescript": "^7.12.13",
|
|
58
|
+
"@types/chai": "^4.2.14",
|
|
59
|
+
"@types/enzyme": "^3.10.8",
|
|
60
|
+
"@types/jest": "^26.0.20",
|
|
61
|
+
"@types/react": "17 || 18",
|
|
62
|
+
"@types/react-dom": "17 || 18",
|
|
63
|
+
"@types/sinon": "^9.0.10",
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
|
65
|
+
"@typescript-eslint/parser": "^4.14.2",
|
|
66
|
+
"babel-jest": "^26.6.3",
|
|
67
|
+
"babel-loader": "^8.2.2",
|
|
68
|
+
"babel-preset-jason": "^6.3.0",
|
|
69
|
+
"chai": "^4.2.0",
|
|
70
|
+
"cherry-pick": "^0.5.0",
|
|
71
|
+
"enzyme": "^3.10.0",
|
|
72
|
+
"enzyme-adapter-react-16": "^1.15.6",
|
|
73
|
+
"eslint": "^7.19.0",
|
|
74
|
+
"eslint-config-prettier": "^7.2.0",
|
|
75
|
+
"eslint-plugin-import": "^2.22.1",
|
|
76
|
+
"eslint-plugin-mocha": "^8.0.0",
|
|
77
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
78
|
+
"eslint-plugin-react": "^7.22.0",
|
|
79
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
80
|
+
"faker": "^5.3.1",
|
|
81
|
+
"install-peers-cli": "^2.2.0",
|
|
82
|
+
"jest": "^26.6.3",
|
|
83
|
+
"lodash": "^4.17.15",
|
|
84
|
+
"postcss": "^8.2.4",
|
|
85
|
+
"prettier": "^2.2.1",
|
|
86
|
+
"rimraf": "^3.0.2",
|
|
87
|
+
"sass": "^1.32.6",
|
|
88
|
+
"sinon": "^9.2.4",
|
|
89
|
+
"typescript": "^4.1.3",
|
|
90
|
+
"webpack": "^5.20.1",
|
|
91
|
+
"webpack-atoms": "^17.1.0",
|
|
92
|
+
"webpack-cli": "^4.5.0"
|
|
93
|
+
},
|
|
94
|
+
"prettier": {
|
|
95
|
+
"printWidth": 150,
|
|
96
|
+
"bracketSpacing": false,
|
|
97
|
+
"trailingComma": "none",
|
|
98
|
+
"singleQuote": true,
|
|
99
|
+
"bracketSameLine": true
|
|
100
|
+
},
|
|
101
|
+
"bugs": {
|
|
102
|
+
"url": "https://github.com/selfcommunity/community-js/issues"
|
|
103
|
+
},
|
|
104
|
+
"gitHead": "4bf7598a9381b1b5281340402b8b3849a7a563fa"
|
|
105
|
+
}
|