pp-is 1.2.0 → 1.2.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 +12 -0
- package/package.json +1 -1
- package/pp-is.js +99 -91
- package/pp-is.min.js +1 -1
package/README.md
CHANGED
|
@@ -94,6 +94,18 @@ Checks if value is a valid Url.
|
|
|
94
94
|
|
|
95
95
|
---
|
|
96
96
|
|
|
97
|
+
#### `isNodeList`
|
|
98
|
+
|
|
99
|
+
Checks if value is a valid NodeList.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
#### `isHTMLCollection`
|
|
104
|
+
|
|
105
|
+
Checks if value is a valid HTMLCollection.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
97
109
|
## How to use ?
|
|
98
110
|
|
|
99
111
|
```javascript
|
package/package.json
CHANGED
package/pp-is.js
CHANGED
|
@@ -1,97 +1,105 @@
|
|
|
1
1
|
/*!!
|
|
2
2
|
* Power Panel pp-is <https://github.com/carlos-sweb/pp-is>
|
|
3
3
|
* @author Carlos Illesca
|
|
4
|
-
* @version 1.2.
|
|
4
|
+
* @version 1.2.1 (2024/02/26 15:00 PM)
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
*/
|
|
7
|
-
(function(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// =======================================================================
|
|
56
|
-
// ^(https?:\/\/)?([w]{3}\.|[w]{3}2\.)? protocol
|
|
57
|
-
// ([w]{3}\.|[w]{3}2\.)? ([a-z\d]+\.)?([a-z\d]+\.[a-z]{2,} Domain name www or www2
|
|
58
|
-
// localhost -> include this word
|
|
59
|
-
// [\d]+\.[\d]+\.[\d]+\.[\d]+ -> add ipv4
|
|
60
|
-
// (\:[\d]+)? -> port
|
|
61
|
-
// ([\??\/?]+[\/;&a-z\d%_.~+=-]*)? -> query url
|
|
62
|
-
// (\#[\/;&a-z\d%_.~+=-]*)? -> hashtag url
|
|
63
|
-
function isUrl( value ){ return /^(https?:\/\/)?([w]{3}\.|[w]{3}2\.)?([a-z\d]+\.)?([a-z\d]+\.[a-z]{2,}|localhost|[\d]+\.[\d]+\.[\d]+\.[\d]+)(\:[\d]+)?([\??\/?]+[\/;&a-z\d%_.~+=-]*)?(\#[\/;&a-z\d%_.~+=-]*)?$/gi.test(value)}
|
|
64
|
-
// =======================================================================
|
|
65
|
-
var base = function( func ){
|
|
66
|
-
// Retornamos una funcion
|
|
67
|
-
return function( value , done ){
|
|
68
|
-
if( isFunction( done ) ){
|
|
69
|
-
if( func( value ) ){
|
|
70
|
-
return done( value )
|
|
71
|
-
}
|
|
72
|
-
}else{
|
|
73
|
-
return func(value)
|
|
74
|
-
}
|
|
7
|
+
;(function(){
|
|
8
|
+
|
|
9
|
+
function is(){
|
|
10
|
+
const getType = ( value )=>Object.prototype.toString.call(value),
|
|
11
|
+
getTypeCompare = (value,expresion) =>(getType(value) === expresion),
|
|
12
|
+
isNodeList = ( value )=>(typeof NodeList === "undefined" ? false : NodeList.prototype.isPrototypeOf(value)),
|
|
13
|
+
isHTMLCollection = ( value )=>(typeof HTMLCollection === "undefined" ? false : HTMLCollection.prototype.isPrototypeOf(value)),
|
|
14
|
+
isArray = ( value )=>getTypeCompare(value,'[object Array]'),
|
|
15
|
+
isRegExp = ( value )=>getTypeCompare(value,'[object RegExp]'),
|
|
16
|
+
isBoolean = ( value )=>value === true || value === false || getType( value ) === '[object Boolean]',
|
|
17
|
+
isDate = ( value )=>getTypeCompare(value,'[object Date]'),
|
|
18
|
+
isElement = ( value )=>!!( value && value.nodeType === 1 ) ,
|
|
19
|
+
isFunction = ( value ) =>getTypeCompare(value,'[object Function]'),
|
|
20
|
+
isNull = ( value )=>getTypeCompare(value,'[object Null]'),
|
|
21
|
+
isNumber = ( value )=>getTypeCompare(value,'[object Number]'),
|
|
22
|
+
isObject = (value )=>getTypeCompare(value,'[object Object]'),
|
|
23
|
+
isString = ( value )=>getTypeCompare(value,'[object String]'),
|
|
24
|
+
isUndefined = ( value )=>getTypeCompare(value,'[object Undefined]'),
|
|
25
|
+
|
|
26
|
+
isEmpty=( value )=>{
|
|
27
|
+
if(isString(value)){ return value === "" }
|
|
28
|
+
else if(isArray(value) ){ return value.length == 0 }
|
|
29
|
+
else if(isObject(value) ){ return Object.keys(value).length === 0}
|
|
30
|
+
return true;
|
|
31
|
+
},
|
|
32
|
+
// =======================================================================
|
|
33
|
+
// Investigar Sobre los dominios de cada pais y de cada segmento comercial o publico personal
|
|
34
|
+
isEmail = ( value )=>{ return /^([a-z0-9_-]+[a-z0-9._-]+?)@([a-z0-9-]+\.[a-z]{2,6}|[a-z0-9]+\.[a-z]{2,6}\.[a-z]{2,6})$/i.test( value )},
|
|
35
|
+
// =======================================================================
|
|
36
|
+
isNaN = ( value )=>(Number.isNaN( parseInt(value))),
|
|
37
|
+
// =======================================================================
|
|
38
|
+
// ^(https?:\/\/)?([w]{3}\.|[w]{3}2\.)? protocol
|
|
39
|
+
// ([w]{3}\.|[w]{3}2\.)? ([a-z\d]+\.)?([a-z\d]+\.[a-z]{2,} Domain name www or www2
|
|
40
|
+
// localhost -> include this word
|
|
41
|
+
// [\d]+\.[\d]+\.[\d]+\.[\d]+ -> add ipv4
|
|
42
|
+
// (\:[\d]+)? -> port
|
|
43
|
+
// ([\??\/?]+[\/;&a-z\d%_.~+=-]*)? -> query url
|
|
44
|
+
// (\#[\/;&a-z\d%_.~+=-]*)? -> hashtag url
|
|
45
|
+
isUrl = ( value )=>{ return /^(https?:\/\/)?([w]{3}\.|[w]{3}2\.)?([a-z\d]+\.)?([a-z\d]+\.[a-z]{2,}|localhost|[\d]+\.[\d]+\.[\d]+\.[\d]+)(\:[\d]+)?([\??\/?]+[\/;&a-z\d%_.~+=-]*)?(\#[\/;&a-z\d%_.~+=-]*)?$/gi.test(value)},
|
|
46
|
+
// =======================================================================
|
|
47
|
+
base = ( func )=>{
|
|
48
|
+
return ( value , done )=>{
|
|
49
|
+
if( isFunction( done ) ){
|
|
50
|
+
if( func( value ) ){
|
|
51
|
+
return done( value )
|
|
52
|
+
}
|
|
53
|
+
}else{
|
|
54
|
+
return func(value)
|
|
75
55
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// =======================================================================
|
|
59
|
+
return {
|
|
60
|
+
isArray:base(isArray),
|
|
61
|
+
isBoolean:base(isBoolean),
|
|
62
|
+
isDate:base(isDate),
|
|
63
|
+
isElement:base(isElement),
|
|
64
|
+
isEmpty:base(isEmpty),
|
|
65
|
+
isFunction:base(isFunction),
|
|
66
|
+
isNull:base(isNull),
|
|
67
|
+
isNumber:base(isNumber),
|
|
68
|
+
isObject:base(isObject),
|
|
69
|
+
isString:base(isString),
|
|
70
|
+
isUndefined:base(isUndefined),
|
|
71
|
+
isEmail:base(isEmail),
|
|
72
|
+
isNaN:base(isNaN),
|
|
73
|
+
isRegExp:base(isRegExp),
|
|
74
|
+
isUrl:base(isUrl),
|
|
75
|
+
isNodeList:base(isNodeList),
|
|
76
|
+
isHTMLCollection:base(isHTMLCollection)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Detect free variable `global` from Node.js. */
|
|
81
|
+
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|
82
|
+
|
|
83
|
+
/** Detect free variable `self`. */
|
|
84
|
+
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
85
|
+
|
|
86
|
+
/** Used as a reference to the global object. */
|
|
87
|
+
var root = freeGlobal || freeSelf || Function('return this')();
|
|
88
|
+
|
|
89
|
+
/** Detect free variable `exports`. */
|
|
90
|
+
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
|
91
|
+
|
|
92
|
+
/** Detect free variable `module`. */
|
|
93
|
+
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
|
94
|
+
|
|
95
|
+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd){
|
|
96
|
+
define(function(){
|
|
97
|
+
return is();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else if( freeModule ){
|
|
101
|
+
freeModule.exports = is()
|
|
102
|
+
}else{
|
|
103
|
+
root.ppIs = is();
|
|
104
|
+
}
|
|
105
|
+
}.call(this))
|
package/pp-is.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
(function(){function e(){const e=e=>Object.prototype.toString.call(e),t=(t,o)=>e(t)===o,o=e=>t(e,"[object Array]"),i=e=>t(e,"[object Function]"),n=e=>t(e,"[object Object]"),s=e=>t(e,"[object String]"),l=e=>(t,o)=>i(o)?e(t)?o(t):void 0:e(t);return{isArray:l(o),isBoolean:l((t=>!0===t||!1===t||"[object Boolean]"===e(t))),isDate:l((e=>t(e,"[object Date]"))),isElement:l((e=>!(!e||1!==e.nodeType))),isEmpty:l((e=>s(e)?""===e:o(e)?0==e.length:!n(e)||0===Object.keys(e).length)),isFunction:l(i),isNull:l((e=>t(e,"[object Null]"))),isNumber:l((e=>t(e,"[object Number]"))),isObject:l(n),isString:l(s),isUndefined:l((e=>t(e,"[object Undefined]"))),isEmail:l((e=>/^([a-z0-9_-]+[a-z0-9._-]+?)@([a-z0-9-]+\.[a-z]{2,6}|[a-z0-9]+\.[a-z]{2,6}\.[a-z]{2,6})$/i.test(e))),isNaN:l((e=>Number.isNaN(parseInt(e)))),isRegExp:l((e=>t(e,"[object RegExp]"))),isUrl:l((e=>/^(https?:\/\/)?([w]{3}\.|[w]{3}2\.)?([a-z\d]+\.)?([a-z\d]+\.[a-z]{2,}|localhost|[\d]+\.[\d]+\.[\d]+\.[\d]+)(\:[\d]+)?([\??\/?]+[\/;&a-z\d%_.~+=-]*)?(\#[\/;&a-z\d%_.~+=-]*)?$/gi.test(e))),isNodeList:l((e=>"undefined"!=typeof NodeList&&NodeList.prototype.isPrototypeOf(e))),isHTMLCollection:l((e=>"undefined"!=typeof HTMLCollection&&HTMLCollection.prototype.isPrototypeOf(e)))}}var t="object"==typeof global&&global&&global.Object===Object&&global,o="object"==typeof self&&self&&self.Object===Object&&self,i=t||o||Function("return this")(),n="object"==typeof exports&&exports&&!exports.nodeType&&exports&&"object"==typeof module&&module&&!module.nodeType&&module;"function"==typeof define&&"object"==typeof define.amd&&define.amd?define((function(){return e()})):n?n.exports=e():i.ppIs=e()}).call(this);
|