-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrLike.js
More file actions
41 lines (33 loc) · 1.19 KB
/
arrLike.js
File metadata and controls
41 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
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
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/javascript/blob/master/LICENSE
*/
// arrLike
// script with some functions related to array like management
// import
import { Arr, Env, Func, Scalar, Vari } from '../index.js';
// export
export default {
// is
// retourne vrai si la variable est comme un tableau (array-like)
// retourne faux si la valeur est un array
is: function(value)
{
let r = false;
if(!Arr.is(value) && !Scalar.is(value) && !Func.is(value) && !Env.isWindow(value))
{
const type = Vari.type(value);
const length = !!value && "length" in value && value.length;
r = type === 'array' || length === 0 || typeof length === "number" && length > 0 && (length - 1) in value;
}
return r;
},
// toArray
// retourne la même valeur si c'est un tableau, sinon converti le array like
// moins stricte que le toArray de obj
toArray: function(value)
{
return Arr.is(value)? value:(this.is(value) ? Array.from(value):null);
}
}