This module copies functionality of core-util-is v1.0.2 for ExtendScript.
npm i ps-util-is
- As a module for scripts that uses this template:
var util = require('ps-util-is');
- As a module for scripts that uses
#include
:
#include "{path_to_bundle}/ps-util-is.jsx"
var util = require(ps-util-is);
The behavior of the typeof operator in ExtendScript differs from node.js:
// ExtendScript
var re = /a*/gim;
$.writeln(typeof re); // function !!!
//Node
var re = /a*/gim;
console.log(typeof re); // object
This module takes core-util-is as "source of truth", so:
// ExtendScript
var re = /a*/gim;
$.writeln(isObject(re)); // true
$.writeln(isRegExp(re)); // true
$.writeln(isFunction(re)); // false
This module will search for Array.isArray() polyfill. For example, ps-scripting-es5shim relies on __class__ property, and code in this repo relies on Object.prototype.toString
Code | isArray | isBoolean | isDate | isError | isFunction | isNull | isNullOrUndefined | isNumber | isObject | isPrimitive | isRegExp | isString | isUndefined |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false | false |
new Number(10) | false | false | false | false | false | false | false | false | TRUE | false | false | false | false |
____ | false | false | false | false | false | false | false | false | false | TRUE | false | TRUE | false |
new String('overconfidence') | false | false | false | false | false | false | false | false | TRUE | false | false | false | false |
false | false | TRUE | false | false | false | false | false | false | false | TRUE | false | false | false |
new Boolean(false) | false | false | false | false | false | false | false | false | TRUE | false | false | false | false |
undefined | false | false | false | false | false | false | TRUE | false | false | TRUE | false | false | TRUE |
null | false | false | false | false | false | TRUE | TRUE | false | false | TRUE | false | false | false |
NaN | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false | false |
[1,2,3] | TRUE | false | false | false | false | false | false | false | TRUE | false | false | false | false |
new Array(1,2,3) | TRUE | false | false | false | false | false | false | false | TRUE | false | false | false | false |
/a*/gim | false | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false |
new RegExp('a*' , 'gim') | false | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false |
new Date(2029,1,1) | false | false | TRUE | false | false | false | false | false | TRUE | false | false | false | false |
{prop: 12345} | false | false | false | false | false | false | false | false | TRUE | false | false | false | false |
new Object({prop: 12345}) | false | false | false | false | false | false | false | false | TRUE | false | false | false | false |
function(x){return x;} | false | false | false | false | TRUE | false | false | false | false | false | false | false | false |
new Function('x','return x;') | false | false | false | false | TRUE | false | false | false | false | false | false | false | false |
new Error('something bad happened') | false | false | false | TRUE | false | false | false | false | TRUE | false | false | false | false |
Code | isArray | isBoolean | isDate | isError | isFunction | isNull | isNullOrUndefined | isNumber | isObject | isPrimitive | isRegExp | isString | isSymbol | isUndefined |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false | false | false |
new Number(10) | false | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
new String('overconfidence') | false | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
false | false | TRUE | false | false | false | false | false | false | false | TRUE | false | false | false | false |
new Boolean(false) | false | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
undefined | false | false | false | false | false | false | TRUE | false | false | TRUE | false | false | false | TRUE |
null | false | false | false | false | false | TRUE | TRUE | false | false | TRUE | false | false | false | false |
NaN | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false | false | false |
[1,2,3] | TRUE | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
new Array(1,2,3) | TRUE | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
/a*/gim | false | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false | false |
new RegExp('a*' , 'gim') | false | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false | false |
new Date(2029,1,1) | false | false | TRUE | false | false | false | false | false | TRUE | false | false | false | false | false |
{prop: 12345} | false | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
new Object({prop: 12345}) | false | false | false | false | false | false | false | false | TRUE | false | false | false | false | false |
function(x){return x;} | false | false | false | false | TRUE | false | false | false | false | false | false | false | false | false |
new Function('x','return x;') | false | false | false | false | TRUE | false | false | false | false | false | false | false | false | false |
new Error('something bad happened') | false | false | false | TRUE | false | false | false | false | TRUE | false | false | false | false | false |
____ | false | false | false | false | false | false | false | false | false | TRUE | false | TRUE | false | false |
Tests will be kept only in github repo. If you want to test on another dataset do the following steps:
- Get files from this repo, then
npm install
- ./test/data/test_data.js change data as you need.
- [OPTIONAL]
nmp run watch
just in case (rebuild bundles). - run ./build/test_bundle.jsx in ESTK, or in target app. This will rewrite ./test/data/ps-util-is-result.js
npm test
see test results in console