qsu 0.5.3 → 1.0.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/.eslintignore +2 -0
- package/.eslintrc.cjs +44 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/qsu.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -21
- package/README.md +522 -158
- package/dist/index.d.ts +57 -0
- package/dist/index.js +343 -0
- package/package.json +55 -32
- package/tsconfig.json +23 -0
- package/.babelrc +0 -7
- package/.eslintrc.js +0 -25
- package/array.js +0 -47
- package/date.js +0 -36
- package/format.js +0 -76
- package/index.js +0 -17
- package/math.js +0 -32
- package/misc.js +0 -7
- package/string.js +0 -145
- package/test/array.spec.js +0 -42
- package/test/date.spec.js +0 -36
- package/test/format.spec.js +0 -56
- package/test/math.spec.js +0 -30
- package/test/misc.spec.js +0 -8
- package/test/string.spec.js +0 -107
- package/test/verify.spec.js +0 -74
- package/verify.js +0 -88
package/verify.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const empty = (data) => {
|
|
2
|
-
if (!data) return true;
|
|
3
|
-
switch (typeof data) {
|
|
4
|
-
case 'string':
|
|
5
|
-
return data.length < 1;
|
|
6
|
-
case 'object':
|
|
7
|
-
if (Array.isArray(data)) {
|
|
8
|
-
return data.length < 1;
|
|
9
|
-
}
|
|
10
|
-
return Object.keys(data).length < 1;
|
|
11
|
-
default:
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const isUrl = (url, withProtocol = false, strict = false) => {
|
|
17
|
-
if (!url || typeof url !== 'string') return false;
|
|
18
|
-
const temp = () => null;
|
|
19
|
-
if (strict && url.indexOf('.') === -1) return false;
|
|
20
|
-
try {
|
|
21
|
-
temp(new URL(`${(withProtocol && url.indexOf('://') === -1) ? 'https://' : ''}${url}`));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const contains = (str, search, exact) => {
|
|
29
|
-
if (!str || !search || (typeof str !== 'string' && typeof str !== 'object')
|
|
30
|
-
|| (typeof str === 'object' && !Array.isArray(str))) return false;
|
|
31
|
-
if (typeof search === 'string') return str.indexOf(search) !== -1;
|
|
32
|
-
for (let i = 0, iLen = search.length; i < iLen; i += 1) {
|
|
33
|
-
if (exact) {
|
|
34
|
-
if (str === search[i]) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
} else if (str.indexOf(search[i]) !== -1) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const is2dArray = (arr) => {
|
|
45
|
-
if (!arr || typeof arr !== 'object' || !Array.isArray(arr)) return false;
|
|
46
|
-
return arr.filter(Array.isArray).length > 0;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const between = (number, range, inclusive = false) => {
|
|
50
|
-
if (!number) throw new Error('Need a value to compare with range');
|
|
51
|
-
if (!range || typeof range !== 'object' || range.length !== 2) throw new Error('You should use range like this: [min, max]');
|
|
52
|
-
const minM = Math.min.apply(Math, [range[0], range[1]]);
|
|
53
|
-
const maxM = Math.max.apply(Math, [range[0], range[1]]);
|
|
54
|
-
return inclusive ? number >= minM && number <= maxM : number > minM && number < maxM;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const length = (data) => {
|
|
58
|
-
if (!data || typeof data === 'undefined') return 0;
|
|
59
|
-
switch (typeof data) {
|
|
60
|
-
case 'object':
|
|
61
|
-
return Array.isArray(data) ? data.length : Object.keys(data).length;
|
|
62
|
-
case 'number':
|
|
63
|
-
case 'bigint':
|
|
64
|
-
return data.toString().length;
|
|
65
|
-
case 'boolean':
|
|
66
|
-
return data ? 4 : 5;
|
|
67
|
-
case 'function':
|
|
68
|
-
return length(data());
|
|
69
|
-
case 'string':
|
|
70
|
-
default:
|
|
71
|
-
return data.length;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const isBotAgent = (userAgent) => {
|
|
76
|
-
if (!userAgent || typeof userAgent !== 'string' || userAgent.length < 1) return false;
|
|
77
|
-
return /bot|naverbot|google|Googlebot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis/i.test(userAgent);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
module.exports = {
|
|
81
|
-
empty,
|
|
82
|
-
isUrl,
|
|
83
|
-
contains,
|
|
84
|
-
is2dArray,
|
|
85
|
-
between,
|
|
86
|
-
length,
|
|
87
|
-
isBotAgent,
|
|
88
|
-
};
|