Util

Wsh. Util

Source:

WSH (Windows Script Host) utility library (similar to Node.js-Util, Lodash).

Requires

Namespaces

types

Methods

(static) cloneDeep(val) → {any}

Source:

Creates a deep clone (recursively clone) of value.

Example
var cloneDeep = Wsh.Util.cloneDeep; // Shorthand

var objSource = {
  s: 's',
  a: [1, [2, 3]],
  o: { nA: 1, nB: { o2: 2 } }
};

var objCloned = cloneDeep(objSource);
console.dir(objCloned);
// Returns: {
//   s: 's',
//   a: [1, [2, 3]],
//   o: { nA: 1, nB: { o2: 2 } } }

console.dir(objSource === objCloned); // false
Parameters:
Name Type Description
val any

The value

Returns:
Type
any

(static) concat(array, …valuesopt) → {Array}

Source:

Creates a new array concatenating array with any additional arrays and/or values.

Example
var concat = Wsh.Util.concat; // Shorthand

concat([1, 2], [3, 4], 5); // [1, 2, 3, 4, 5]

var srcArray = [1];

concat(srcArray, 2, [3], [[4]]); // [1, 2, 3, [4]]
console.dir(srcArray); // [1] The source array is not changed
Parameters:
Name Type Attributes Description
array Array

The array to concatenate

values any <optional>
<repeatable>

The values to concatenate

Returns:

Returns the new concatenated array

Type
Array

(static) conv2DArrayToObj(arrays, optionsopt) → {object}

Source:

Converts a 2D-array to a associative-array.

Example
var conv2DArrayToObj = Wsh.Util.conv2DArrayToObj; // Shorthand

var srcArray = [
  'This CSV was output from Tuckn Hoge system',
  ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'], // to be header
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  [true, false, null, undefined, NaN, Infinity, ''],
  ['=SUM(X1:Y10)', '=TODAY()', '2020/1/1', '\'007', '日本語'],
  ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']
];

conv2DArrayToObj(srcArray, { beginRow: 2 });
// Returns: [
//   {
//      A: 0,
//      B: 1,
//      C: 2,
//      D: 3,
//      E: 4,
//      F: 5,
//      G: 6,
//      H: 7,
//      I: 8,
//      J: 9,
//      K: 10,
//      L: 11 },
//   {
//      A: true,
//      B: false,
//      C: null,
//      D: undefined,
//      E: NaN,
//      F: Infinity,
//      G: '',
//      H: undefined,
//      I: undefined,
//      J: undefined,
//      K: undefined,
//      L: undefined },
//   {
//      A: '=SUM(X1:Y10)',
//      B: '=TODAY()',
//      C: '2020/1/1',
//      D: '\'007',
//      E: '日本語',
//      F: undefined,
//      G: undefined,
//      H: undefined,
//      I: undefined,
//      J: undefined,
//      K: undefined,
//      L: undefined },
//   {
//      A: 'a',
//      B: 'b',
//      C: 'c',
//      D: 'd',
//      E: 'e',
//      F: 'f',
//      G: 'g',
//      H: 'h',
//      I: 'i',
//      J: 'j',
//      K: 'k',
//      L: 'l' } ];
Parameters:
Name Type Attributes Description
arrays array

The 2D-Array to convert.

options typeConv2DArrayToObjOptions <optional>

Optional parameters.

Returns:
  • A converted object.
Type
object

(static) convToVBArray(arr) → {VBArray}

Source:

Converts VBArray to JS-Array. @FIXME ScriptControl does not work on Windows 64bit

Parameters:
Name Type Description
arr array

The array to convert.

Returns:
  • A VBArray
Type
VBArray

(static) createDateString(fmtopt, dateObjopt) → {string}

Source:

Create a date string.

Example
var dateParser = Wsh.Util.createDateString; // Shorthand

dateParser(); // Equal with dateParser('yyyyMMddTHHmmss+hhmm')
// Returns: '20150204T065424+0900'

dateParser('yyyy-MM'); // '2015-02'
dateParser('yy/MM/dd'); // '15/02/04'
dateParser('HH:mm:ss'); // '06:54:24'
Parameters:
Name Type Attributes Default Description
fmt string <optional>
'yyyyMMddTHHmmss+hhmm'

The date format.

dateObj Date <optional>
new Date()

The Data object to parse.

Returns:
  • Created a date string.
Type
string

(static) endsWith(val, target, positionopt, ignoresCaseopt) → {boolean}

Source:

Checks if string ends with the given target string.

Example
var endsWith = Wsh.Util.endsWith; // Shorthand

// true
endsWith('abc', 'c');
endsWith('abc', 'bc');
endsWith('abc', 'b', 2);
endsWith('abc', 'Bc', 'i');
endsWith('abc', 'Bc', null, 'i');

// false
endsWith('abc', 'b');
endsWith('abc', 'Bc');

// Note: If the second argument is '', returns true.
endsWith('abc', ''); // ture
endsWith([1], ''); // true
Parameters:
Name Type Attributes Default Description
val string

The string to inspect.

target string

The stiring to search for.

position number | 'i' <optional>
0

The position to search from.

ignoresCase boolean | 'i' <optional>
false

To Specify true or 'i' will be case insensitive.

Returns:
  • Returns true if string ends with target, else false.
Type
boolean

(static) extend(…objects) → {object}

Source:

Shallow merge. Note the difference from Wsh.Util.merge

Parameters:
Name Type Attributes Description
objects object <repeatable>
Returns:

A merged object that is the 1st Object of the arguments

Type
object

(static) get(obj, propPath, defaultValueopt) → {any}

Source:

Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.

Example
var util = Wsh.Util; // Shorthand

var src = { a: 1, b: { B: 2 }, c: [3, 4] };
util.get(src, 'a'); // 1
util.get(src, 'A'); // undefined
util.get(src, 'A', 'defVal'); // 'defVal'

util.get(src, 'b'); // { B: 2 }
util.get(src, 'b.B'); // 2
util.get(src, ['b', 'B']); // 2

// If the result is Object or Array, it's called by reference.
var getVal = util.get(src, 'b');
if (getVal === src.b) // true

util.get(src, 'c'); // [3, 4]
util.get(src, 'c.1') // 4

util.get({ empArray: [], empObj: {} }, 'empArray', 'def') // []
util.get({ empArray: [], empObj: {} }, 'empObj', 'def') // {}
Parameters:
Name Type Attributes Description
obj object

The object to query.

propPath Array.<string> | string

The path of the property to get.

defaultValue any <optional>

The value returned for undefined resolved values.

Returns:
  • A extracted value.
Type
any

(static) hasContent(val) → {boolean}

Source:

Checks if a value is not empty.

Example
var hasContent = Wsh.Util.hasContent; // Shorthand

// true
hasContent(true);
hasContent(false);
hasContent(NaN);
hasContent(Infinity);
hasContent(0);
hasContent([1]);
hasContent({ a: 'A' });
hasContent('a');
hasContent(new Error());
hasContent(new Date());
hasContent(/^regExp$/);

// false
hasContent(undefined);
hasContent(null);
hasContent([]);
hasContent({});
hasContent('');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Return true if a value is not empty. else false.
Type
boolean

(static) hasIn(obj, propertiesNames) → {boolean}

Source:

Checks if the object has the properties.

Example
var hasIn = Wsh.Util.hasIn; // Shorthand

var objDeep = { a: { b: { c: 'C' } } };
hasIn(objDeep, 'a'); // true
hasIn(objDeep, 'b'); // false
hasIn(objDeep, 'a.b'); // true
hasIn(objDeep, 'a.B'); // false
hasIn(objDeep, ['a', 'b']); // true
hasIn(objDeep, 'a.b.c'); // true

// Going up the prototype chain
var Constractor = function () { this.a = 'A'; };
Constractor.prototype.myProto = 'val';

var instance = new Constractor();
hasInObj(instance, 'a'); // true
hasInObj(instance, 'myProto'); // true
hasInObj(instance, 'prototype'); // false
hasInObj(instance, 'prototype.myProto'); // false
hasInObj(instance, 'hasOwnProperty'); // true
hasInObj(instance, 'toString'); // true
Parameters:
Name Type Description
obj object

The object to query.

propertiesNames array | string

The path to check.

Returns:
Type
boolean

(static) hasInObj(obj, prop) → {boolean}

Source:

Check if the Object has a property. Point: Going up the prototype chain. Note the difference from Wsh.Util.hasOwnProp

Example
var hasInObj = Wsh.Util.hasInObj; // Shorthand

var objDeep = { a: { b: { c: 'C' } } };
hasInObj(objDeep, 'a'); // true
hasInObj(objDeep, 'b'); // false

// Going up the prototype chain
var Constractor = function () { this.a = 'A'; };
Constractor.prototype.myProto = 'val';

var instance = new Constractor();
hasInObj(instance, 'a'); // true
hasInObj(instance, 'myProto'); // true (prototype)
hasInObj(instance, 'prototype'); // false
hasInObj(instance, 'hasOwnProperty'); // true (prototype)
hasInObj(instance, 'toString'); // true (prototype)
Parameters:
Name Type Description
obj object
prop string
Returns:
Type
boolean

(static) hasOwnProp(obj, prop) → {boolean}

Source:

Check if the Object has a property. Point: No going up the prototype chain. Note the difference from Wsh.Util.hasInObj.

Example
var hasOwnProp = Wsh.Util.hasOwnProp; // Shorthand

var objDeep = { a: { b: { c: 'C' } } };
hasOwnProp(objDeep, 'a'); // true
hasOwnProp(objDeep, 'b'); // false

// No going up the prototype chain
var Constractor = function () { this.a = 'A'; };
Constractor.prototype.myProto = 'val';

var instance = new Constractor();
hasOwnProp(instance, 'a'); // true
hasOwnProp(instance, 'myProto'); // false (prototype)
hasOwnProp(instance, 'prototype'); // false
hasOwnProp(instance, 'hasOwnProperty'); // false (prototype)
hasOwnProp(instance, 'toString'); // false (prototype)
Parameters:
Name Type Description
obj object
prop string
Returns:
Type
boolean

(static) inArray(value, array, fromIndexopt) → {number}

Source:

Gets the index at which the first occurrence of value is found.

Example
var inArray = Wsh.Util.inArray; // Shorthand

inArray('A', ['A', 'B', 'C']); // 0
inArray('B', ['A', 'B', 'C']); // 1
inArray('C', ['A', 'B', 'C']); // 2
inArray('B', ['A', 'B', 'A', 'B']); // 1
inArray('B', ['A', 'B', 'A', 'B'], 2); // 3
inArray({ b: 'B' }, ['A', { b: 'B' }, 'C']); // 1
Parameters:
Name Type Attributes Default Description
value any

The value of search for.

array Array

The array to check.

fromIndex number <optional>
0

The index of search from.

Returns:

A index number of array. If no matching, return -1.

Type
number

(static) includes(collection, val, fromIndexopt, ignoresCaseopt) → {boolean}

Source:

Checks if value is in collection (Array, Object, String).

Example
var includes = Wsh.Util.includes; // Shorthand

includes('abcd', 'bc'); // true
includes('abcd', 'Bc'); // false
includes('abcd', 'Bc', 'i'); // true
includes('abcd', 'Bc', null, 'i'); // true

includes([1, 2, 3, 4], 3); // true
includes({ a: 1, b: 'B' }, 'B'); // true
includes({ a: 1, b: 'B' }, 'b'); // false

includes([1, 2, { c: 'C' }], { c: 'C' }); // false <- Note this

var objC = { c: 'C' };
includes([1, 2, objC], objC); // true
Parameters:
Name Type Attributes Default Description
collection array | Object | string

The collection to inspect.

val any

The value to inspect.

fromIndex number | 'i' <optional>
0

The index to search from.

ignoresCase boolean | 'i' <optional>
false

To Specify true or 'i' will be case insensitive.

Returns:
Type
boolean

(static) indexOf(array, value, fromIndexopt) → {number}

Source:

Gets the index at which the first occurrence of value is found. Note that only the arguments order is different from Wsh.Util.inArray.

Example
var indexOf = Wsh.Util.indexOf; // Shorthand

indexOf(['A', 'B', 'C'], 'A'); // 0
indexOf(['A', 'B', 'C'], 'B'); // 1
indexOf(['A', 'B', 'C'], 'C'); // 2
indexOf(['A', 'B', 'A', 'B'], 'B'); // 1
indexOf(['A', 'B', 'A', 'B'], 'B', 2); // 3
indexOf(['A', { b: 'B' }, 'C'], { b: 'B' }); // 1
Parameters:
Name Type Attributes Default Description
array Array

The array to check.

value any

The value of search for.

fromIndex number <optional>
0

The index of search from.

Returns:

A index number of array. If no matching, return -1.

Type
number

(static) inspect(val) → {string}

Source:

Converts a value to formatted string.

Example
var util = Wsh.Util; // Shorthand

util.inspect(undefined); // 'undefined'
util.inspect(null); // 'null'
util.inspect(true); // 'true'
util.inspect(NaN); // 'NaN'
util.inspect('Foo'); // '"Foo"'
util.inspect('  '); // '"  "'

util.inspect([1, NaN, '3']);
// '[
//    0: 1,
//    1: NaN,
//    2: "3",
// ]'

util.inspect({ a: [1, 2], b: true, o: { c: 'C' } });
// '{
//   a: [
//     0: 1,
//     1: 2
//   ],
//   b: true,
//   o: {
//     c: "C"
//   }
// }'
Parameters:
Name Type Description
val any

The value to format.

Returns:
  • A formatted string.
Type
string

(static) isArray(val) → {boolean}

Source:

Checks if a value is classified as an Array object.

Example
var isArray = Wsh.Util.isArray; // Shorthand

// true
isArray([]);
isArray([1, 2, 3]);

// false
isArray(undefined);
isArray('foo bar');
isArray({ a: 'A', b: 'B' });
isArray((function () { return arguments; })());
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is an Array, else false.
Type
boolean

(static) isASCII(val) → {boolean}

Source:

Checks if a value is composed of ASCII code only.

Example
var isASCII = Wsh.Util.isASCII; // Shorthand

// true
isASCII('0123456789');
isASCII('abcdefghijklmnopqrstuvwxyz');
isASCII('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~');
isASCII('\t\n\r ');

// false
isASCII('abシーd');
isASCII('偽');
isASCII(0);
isASCII(true);
isASCII([1, 2, 3]);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is composed of ASCII code only.
Type
boolean

(static) isBoolean(val) → {boolean}

Source:

Checks if a value is classified as a Boolean object.

Example
var isBoolean = Wsh.Util.isBoolean; // Shorthand

// true
isBoolean(true);
isBoolean(false);

// false
isBoolean(undefined);
isBoolean(null);
isBoolean(1);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a Boolean, else false.
Type
boolean

(static) isDeepStrictEqual(valA, valB) → {boolean}

Source:

Check if there is deep strict equality between valA and valB. Note that if a property of the value has a function, returns false.

Example
var isEqual = Wsh.Util.isDeepStrictEqual; // Shorthand

isEqual(0, 0); // true
isEqual(NaN, NaN); // true
isEqual('foo', 'foo'); // true
isEqual([1, 2, 3], [1, 2, 3]); // true

var objA = { s: 's', a: [1, [2, 3]], o: { nA: 1, nB: { o2: 2 } } };
var objB = { s: 's', a: [1, [2, 3]], o: { nA: 1, nB: { o2: 2 } } };
isEqual(objA, objB); // true

isEqual(0, 3); // false
isEqual([1, 2, 3], [1, 2]); // false

var objFnA = { val: 'value', func: function () { return 1; } };
var objFnB = { val: 'value', func: function () { return 1; } };
isEqual(objFnA, objFnB); // false
Parameters:
Name Type Description
valA any

The value to check.

valB any

The value to check.

Returns:
  • Returns true if there is deep strict equality between valA and valB. Otherwise, returns false.
Type
boolean

(static) isEmpty(val) → {boolean}

Source:

Checks if a value is an empty enumerable object or non enumerable object.

Example
var isEmpty = Wsh.Util.isEmpty; // Shorthand

// true
isEmpty([]);
isEmpty({});
isEmpty('');
// true - Because non enumerable object
isEmpty(undefined);
isEmpty(null);
isEmpty(true);
isEmpty(false);
isEmpty(NaN);
isEmpty(Infinity);
isEmpty(0);
isEmpty(99);
isEmpty(new Error());
isEmpty(new Date());
isEmpty(new RegExp(''));

// false
isEmpty([1]);
isEmpty({ a: 'A' });
isEmpty('a');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if value is an empty enumerable object, else false
Type
boolean

(static) isEqual()

Source:
See:

Another name of Wsh.Util.isDeepStrictEqual

(static) isError(val) → {boolean}

Source:

Checks if a value is classified as an Error object.

Example
var isError = Wsh.Util.isError; // Shorthand

isError(new Error()); // true
isError(undefined); // false
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is an Error, else false.
Type
boolean

(static) isFalseLike(val) → {boolean}

Source:

Checks if a value is false-like.

Example
var isFalseLike = Wsh.Util.isFalseLike; // Shorthand

// true
isFalseLike(false);
isFalseLike(undefined);
isFalseLike(null);
isFalseLike(0);
isFalseLike(NaN);
isFalseLike('');
isFalseLike('false');
isFalseLike('FALSE');

// false
isFalseLike(true);
isFalseLike([]);
isFalseLike({});
isFalseLike('a');
isFalseLike(99);
isFalseLike(Infinity);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is false-like.
Type
boolean

(static) isFunction(val) → {boolean}

Source:

Checks if a value is classified as a Function object.

Example
var isFunction = Wsh.Util.isFunction; // Shorthand

isFunction(function (a) { return a * a; }); // true
isFunction({ a: 'A', b: 'B' }); // false
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a Function, else false.
Type
boolean

(static) isJapaneseLike(str) → {boolean}

Source:

[W.I.P] Check if a name is like Japanese.

Parameters:
Name Type Description
str string

The string to check.

Returns:
Type
boolean

(static) isMailAddress(val) → {boolean}

Source:

Check if a value is the string of mail-address.

Example
var isMailAddress = Wsh.Util.isMailAddress; // Shorthand

// true
isMailAddress('tuckn333@gmail.com');
isMailAddress('tuckn333@gmail.com');
isMailAddress('tuckn333@[11.22.33.44]');

// false
isEmpty('tuckn333.github.gmail.com');
Parameters:
Name Type Description
val string

The value to check.

Returns:
  • Returns true if value is the string of mail-address.
Type
boolean

(static) isNumber(val) → {boolean}

Source:

Checks if a value is classified as a Number object.

Example
var isNumber = Wsh.Util.isNumber; // Shorthand

// true
isNumber(3);
isNumber(3.14);
isNumber(-1);
isNumber(NaN);
isNumber(Infinity);

// false
isNumber('3');
isNumber(true);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a Number, else false.
Type
boolean

(static) isObject(val) → {boolean}

Source:

Checks if a value is classified as an Object.

Example
var isObject = Wsh.Util.isObject; // Shorthand

// true
isObject({});
isObject({ a: 'A', b: 'B' });
isObject([1, 2, 3]);
isObject(function (a) { return a * a; });
isObject((function () { return arguments; })());
isObject(new Error());
isObject(new Date());
isObject(new RegExp('\\.js$'));

// false
isObject(undefined);
isObject(true);
isObject(0);
isObject('Foo Bar');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is JS-language type of Object.
Type
boolean

(static) isObjectLike(val) → {boolean}

Source:

Checks if a value is classified as an Object and not Function.

Example
var isObjectLike = Wsh.Util.isObjectLike; // Shorthand

// true
isObjectLike({});
isObjectLike({ a: 'A', b: 'B' });
isObjectLike([1, 2, 3]);
isObjectLike((function () { return arguments; })());
isObjectLike(new Error());
isObjectLike(new Date());
isObjectLike(new RegExp('\\.js$'));

// false
isObjectLike(function (a) { return a * a; });
isObjectLike(undefined);
isObjectLike(true);
isObjectLike(0);
isObjectLike('Foo Bar');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if value is Object like.
Type
boolean

(static) isPhoneNumberInJapan(val) → {boolean}

Source:

[W.I.P] 日本国内の電話番号(携帯番号も含む)か判定する

Parameters:
Name Type Description
val string

The value to check.

Returns:
Type
boolean

(static) isPhoneNumberLikeInJapan(str) → {boolean}

Source:

[W.I.P] 最後の一桁足りないけど、おそらく日本国内の電話番号

Parameters:
Name Type Description
str string

The string to check.

Returns:
Type
boolean

(static) isPlainObject(val) → {boolean}

Source:

Checks if a value is classified as a plain Object.

Example
var isPlainObject = Wsh.Util.isPlainObject; // Shorthand

// true
isPlainObject({});
isPlainObject({ a: 'A', b: 'B' });
isPlainObject((function () { return arguments; })());

// false
isPlainObject([1, 2, 3]);
isPlainObject(new Error());
isPlainObject(new Date());
isPlainObject(new RegExp('\\.js$'));
isPlainObject(function (a) { return a * a; });
isPlainObject(undefined);
isPlainObject(true);
isPlainObject(0);
isPlainObject('Foo Bar');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if value is a plain Object.
Type
boolean

(static) isPlaneTextFileExt(str) → {boolean}

Source:

[W.I.P] Check if a file is plane text.

Parameters:
Name Type Description
str string

The string to check.

Returns:
Type
boolean

(static) isPureNumber(val) → {boolean}

Source:

Checks if a value is classified as a Number object and not NaN or Infinity.

Example
var isPureNumber = Wsh.Util.isPureNumber; // Shorthand

// true
isPureNumber(3);
isPureNumber(3.14);
isPureNumber(-1);

// false
isPureNumber(NaN);
isPureNumber(Infinity);
isPureNumber('3');
isPureNumber(true);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a Number, else false.
Type
boolean

(static) isSameMeaning(valA, valB) → {boolean}

Source:

Check if two values are the same meaning.

Example
var isSameMeaning = Wsh.Util.isSameMeaning; // Shorthand

// true
isSameMeaning('', '');
isSameMeaning('abc', 'abc');
isSameMeaning('abc', 'ABC');
isSameMeaning('真', '真');
isSameMeaning('\t\n\r', '\t\n\r');
isSameMeaning(0, 0);
isSameMeaning('0', 0);

// false
isSameMeaning('', ' ');
isSameMeaning('abc', 'abd');
isSameMeaning('偽', '真');
isSameMeaning([], []);
isSameMeaning([1], [1]);
Parameters:
Name Type Description
valA number | string

The value to check.

valB number | string

The value to check.

Returns:
  • Returns true If the two values are the same meaning.
Type
boolean

(static) isSolidArray(val) → {boolean}

Source:

Checks if a value is classified as an Array object and length > 0.

Example
var isSolidArray = Wsh.Util.isSolidArray; // Shorthand

// true
isSolidArray([1, 2, 3]);

// false
isSolidArray([]);
isSolidArray(undefined);
isSolidArray('foo bar');
isSolidArray({ a: 'A', b: 'B' });
isSolidArray((function () { return arguments; })());
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is an Array and length > 0, else false.
Type
boolean

(static) isSolidObject(val) → {boolean}

Source:

Checks if a value is classified as a plain Object and not empty.

Example
var isSolidObject = Wsh.Util.isSolidObject; // Shorthand

// true
isSolidObject({ a: 'A', b: 'B' });
isSolidObject((function () { return arguments; })());

// false
isSolidObject({});
isSolidObject([1, 2, 3]);
isSolidObject(function (a) { return a * a; });
isSolidObject(new Error());
isSolidObject(new Date());
isSolidObject(new RegExp('\\.js$'));
isSolidObject(undefined);
isSolidObject(true);
isSolidObject(0);
isSolidObject('Foo Bar');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a plain Object and not empty.
Type
boolean

(static) isSolidString(val) → {boolean}

Source:

Checks if a value is classified as a String object and not empty.

Example
var isSolidString = Wsh.Util.isSolidString; // Shorthand

// true
isSolidString('  ');
isSolidString('Hello world!');

// false
isSolidString('');
isSolidString(3);
isSolidString(true);
isSolidString(['foo', 'bar']);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a String and not empty, else false.
Type
boolean

(static) isString(val) → {boolean}

Source:

Checks if a value is classified as a String object.

Example
var isString = Wsh.Util.isString; // Shorthand

// true
isString('');
isString('  ');
isString('Hello world!');

// false
isString(3);
isString(true);
isString(['foo', 'bar']);
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is a String, else false.
Type
boolean

(static) isTrueLike(val) → {boolean}

Source:

Checks if a value is not false-like.

Example
var isTrueLike = Wsh.Util.isTrueLike; // Shorthand

// true
isTrueLike(true);
isTrueLike([]);
isTrueLike({});
isTrueLike('a');
isTrueLike(99);
isTrueLike(Infinity);

// false
isTrueLike(false);
isTrueLike(undefined);
isTrueLike(null);
isTrueLike(0);
isTrueLike(NaN);
isTrueLike('');
isTrueLike('false');
isTrueLike('FALSE');
Parameters:
Name Type Description
val any

The value to check.

Returns:
  • Returns true if the value is true-like.
Type
boolean

(static) last(array) → {any}

Source:

Gets the last element of an array.

Example
var last = Wsh.Util.last; // Shorthand

last([1, 2, 3, 4]); // 4
last(['a', 'b', 'c', 'd']); // 'd'
last([]); // undefined
last('Foo Bar'); // undefined
last({ a: 'A', b: 'B' }); // undefined
Parameters:
Name Type Description
array Array

The Array to ckeck.

Returns:
  • A element of array.
Type
any

(static) lastIndexOf(array, valueopt, fromIndexopt) → {number}

Source:

Gets the index at which the last occurrence of value is found in array.

Example
var lastIndexOf = Wsh.Util.lastIndexOf; // Shorthand

lastIndexOf(['A', 'B', 'C'], 'C'); // 2
lastIndexOf(['A', 'B', 'C'], 'B'); // 1
lastIndexOf(['A', 'B', 'C'], 'A'); // 0
lastIndexOf(['A', 'B', 'A', 'B'], 'B'); // 3
lastIndexOf(['A', 'B', 'A', 'B'], 'B', 2); // 1
lastIndexOf(['A', { b: 'B' }, 'C'], { b: 'B' }); // 1
Parameters:
Name Type Attributes Default Description
array Array

The Array to ckeck.

value any <optional>

The value of search for.

fromIndex number <optional>
array.length - 1

The index to search from.

Returns:

A index of the matched value, else -1.

Type
number

(static) merge(…objects) → {object}

Source:

Deep merge (recursively merge). Note the difference from Wsh.Util.extend

Example
var merge = Wsh.Util.merge; // Shorthand

var objTarget = { a: 'A1', b: { p: 'Bp1', q: 'Bq1' } };
var objSource = { a: 'A2', b: { p: 'Bp2' } };
var mergedObj = merge(objTarget, objSource);
// Returns: { a: 'A2', b: { p: 'Bp2', q: 'Bq1' } };

console.dir(objTarget === mergedObj); // true
// The target Object is mutated
Parameters:
Name Type Attributes Description
objects object <repeatable>
Returns:

A merged object that is the 1st Object of the arguments

Type
object

(static) objToStr(obj, prefixopt, postfixopt) → {string}

Source:

[W.I.P] convert a Object to string

Parameters:
Name Type Attributes Default Description
obj object
prefix string <optional>
' '
postfix string <optional>
\r\n
Returns:
Type
string

(static) obtainPropVal(obj, propertiesNames, defaultValueopt) → {any}

Source:

Note that it's almost the same as Wsh.Util.get, but treats defaultValue differently

Example
var obtain = Wsh.Util.obtainPropVal; // Shorthand

var src = { a: 1, b: { B: 2 }, c: [3, 4] };
obtain(src, 'a'); // 1
obtain(src, 'A'); // undefined
obtain(src, 'A', 'defVal'); // 'defVal'

obtain(src, 'b'); // { B: 2 }
obtain(src, 'b.B'); // 2
obtain(src, ['b', 'B']); // 2

obtain(src, 'c'); // [3, 4]
obtain(src, 'c.1') // 4

obtain({ empArray: [], empObj: {} }, 'empArray', 'def') // 'def'
obtain({ empArray: [], empObj: {} }, 'empObj', 'def') // 'def'
Parameters:
Name Type Attributes Description
obj object

The object to query.

propertiesNames Array.<string> | string

The path of the property to get.

defaultValue any <optional>

The value returned for undefined resolved values.

Returns:
  • A extracted value.
Type
any

(static) parseCsvTo2DArray(csvText, optionsopt) → {Array}

Source:

Parses a CSV text to Two dimensions array.

Example
var parseCsvTo2DArray = Wsh.Util.parseCsvTo2DArray; // Shorthand

var csvTxt = 'This CSV was output from Tuckn Hoge system\r\n'
  + 'A,B,C,D,E,F,G,H,I,J,K,L\r\n'
  + '0,1,2,3,4,5,6,7,8,9,10,11\r\n'
  + 'a,b,c,d,e,f,g,h,i,j,k,l\r\n'
  + '\r\n'
  + 'true,false,null,undefined,NaN,Infinity\r\n'
  + '=SUM(X1:Y10),=TODAY(),2020/1/1,\'007,Has Space,日本語,I say "Yes!","Line\r\n'
  + 'Break"'

parseCsvTo2DArray(csvTxt);
// Returns: [
//   ['This CSV was output from Tuckn Hoge system'],
//   ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'],
//   ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'],
//   ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'],
//   [''],
//   ['true', 'false', 'null', 'undefined', 'NaN', 'Infinity'],
//   ['=SUM(X1:Y10)',
//     '=TODAY()',
//     '2020/1/1',
//     '\'007',
//     'Has Space',
//     '日本語',
//     'I say "Yes!"',
//     '"Line\r\nBreak"' ]]
Parameters:
Name Type Attributes Description
csvText string

The CSV-format string to parse.

options typeParseCsvTo2DArrayOptions <optional>

Optional parameters

Returns:
  • A parsed array
Type
Array

(static) parseDateLiteral(str, dateObjopt) → {string}

Source:

Parses the date template literal to a date string.

Example
var parse = Wsh.Util.parseDateLiteral; // Shorthand

// If the current date is 2020/1/2 15:4:5
parse('#{yyyyMMdd}'); // '20200102'
parse('#{yyyy-MM-dd}'); // '2020-01-02'
parse('#{yyyy}-#{MM}-#{dd}');  // '2020-01-02'
parse('#{yyyy-MM-ddTHH:mm:ss}');  // '2020-01-02T15:04:05'
parse('#{yyyyMMddTHHmmss+hhmm}'); // '20200102T150405+0900

parse('C:\\My Data\\#{yyyy-MM-dd}.txt');
// Returns: 'C:\My Data\2020-01-02.txt'

parse('\\\\MyNas\\#{yyyy}\\#{MM}\\#{dd}');
// Returns: '\\MyNas\2020\01\02'

// Calculation with square brackets `[]`
parse('#{yyyy-MM-1-dd}'); // '2020-01-1-02'
parse('#{yyyy-[MM - 1]-dd}'); // '2019-12-02'
parse('#{yyyy}-#{[MM-1]}-#{dd}'); // '2020-12-02'
parse('#{yy/M/[d - 2]}'); // '19/12/31'
parse('#{yy}#{[MM * 4]}'); // '2004'
parse('#{[yyyy + 4]}-#{MM}'); // '2024-01'
Parameters:
Name Type Attributes Default Description
str string

The string with embedded expressions.

dateObj Date <optional>
new Date()

The Data object to parse.

Returns:
  • The parsed string.
Type
string

(static) parseDateSchema(dateSchema, dateObjopt) → {string}

Source:

Parses the date schema to a date string.

Example
var parser = Wsh.Util.parseDateSchema; // Shorthand
var dt = new Date(2020, 0, 2, 15, 4, 5);

parse('yyyyMMdd', dt); // '20200102'
parse('yyyy-MM-dd', dt); // '2020-01-02'
parse('yyyy-MM', dt); // '2020-01'
parse('yyyy-MM-1', dt); // '2020-01-1'
parse('yyyy-[MM - 1]', dt); // '2019-12'
parse('yyyy-[MM-1]', dt); // '2019-12'
parse('[yyyy + 4]-MM', dt); // '2024-01'
parse('yy[MM * 4]', dt); // '2004'
parse('yy/M/d', dt); // '20/1/2'
parse('yyyy-MM-ddTHH:mm:ss', dt); // '2020-01-02T15:04:05'
parse('yyyy/M/d H:m:s', dt); // '2020/1/2 15:4:5'
parse('yyyyMMddTHHmmss+hhmm', dt)).toMatch(new RegExp('20200102T150405\\+\\d{4}')
parse('\\yyyy\\MM\\dd', dt); // '\\2020\\01\\02'
Parameters:
Name Type Attributes Default Description
dateSchema string

The string of Date literal.

dateObj Date <optional>
new Date()

The Data object to parse.

Returns:
  • The parsed string.
Type
string

(static) parseTemplateLiteral(str, schema) → {string}

Source:

Converts a schema object to a string.

Example
var parser = Wsh.Util.parseTemplateLiteral; // Shorthand

var schema = { comp: 'MYPC1234', share: 'C$', file: 'cache.db' };
parser('cp \\\\${comp}\\${share}\\${file} .\\tmp', schema);
// Returns: cp \\MYPC1234\C$\cache.db .\tmp

parser('No Template Literal', schema));
// Returns: 'No Template Literal'
Parameters:
Name Type Description
str string

The string with embedded expressions. Ex. ${valName}

schema object

Ex. { valName: 'val' }

Returns:
  • The parsed string.
Type
string

(static) set(obj, propPath, valueopt) → {object}

Source:

Sets the value at path of object. If a portion of path doesn't exist, it's created.

Example
var set = Wsh.Util.set; // Shorthand

var obj = { a: 1, b: 'B' };
set(obj, 'a', 'A'); // Returns: { a: 'A', b: 'B' }
// obj is modified. { a: 'A', b: 'B' }

var obj = { a: [{ B: 2 }, { C: 3 }] };
set(obj, 'a.1.C', 99); // Returns: { a: [{ B: 2 }, { C: 99 }] }
// obj is modified. { a: [{ B: 2 }, { C: 99 }] }

set(obj, ['a', 0], 'foo'); // Returns: { a: ['foo', { C: 99 }] }
// obj is modified. { a: ['foo', { C: 99 }] }
Parameters:
Name Type Attributes Description
obj object

The object to modify.

propPath Array.<string> | string

The path of the property to set.

value any <optional>

The value to set.

Returns:
  • The modified obj.
Type
object

(static) startsWith(val, target, positionopt, ignoresCaseopt) → {boolean}

Source:

Checks if string starts with the given target string.

Example
var startsWith = Wsh.Util.startsWith; // Shorthand

// true
startsWith('abc', 'a');
startsWith('abc', 'ab');
startsWith('abc', 'b', 1);
startsWith('abc', 'aB', 'i');
startsWith('abc', 'aB', null, 'i');

// false
startsWith('abc', 'b');
startsWith('abc', 'aB');

// Note: If the second argument is '', returns true.
startsWith('abc', ''); // ture
startsWith([1], ''); // true
Parameters:
Name Type Attributes Default Description
val string

The string to inspect.

target string

The stiring to search for.

position number | 'i' <optional>
0

The position to search from.

ignoresCase boolean | 'i' <optional>
false

To Specify true or 'i' will be case insensitive.

Returns:
  • Returns true if string starts with target, else false.
Type
boolean

(static) stringify2DArrayToCsv(arrays, optionsopt) → {string}

Source:

Converts a 2D-Array to a CSV text (CSV.stringify).

Example
var stringify2DArrayToCsv = Wsh.Util.stringify2DArrayToCsv; // Shorthand

var array2D = [
  ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'],
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  [true, false, null, undefined, NaN, Infinity, ''],
  ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l']
];

stringify2DArrayToCsv(array2D);
// Returns: 'A,B,C,D,E,F,G,H,I,J,K,L\r\n'
//   + '0,1,2,3,4,5,6,7,8,9,10,11\r\n'
//   + 'true,false,,NaN,Infinity,\r\n' // null to empty, undefined is ignored
//   + 'a,b,c,d,e,f,g,h,i,j,k,l\r\n'
Parameters:
Name Type Attributes Description
arrays array

The 2D-Array to convert.

options typeStringify2DArrayToCsvOptions <optional>

Optional parameters.

Returns:
  • A converted string.
Type
string

(static) throwTypeError(trueType, moduleTitle, functionName, errVal)

Source:

Throws an Error that caused by an invalid type of argument.

Example
var throwTypeError = Wsh.Util.throwTypeError; // Shorthand

var myFunc = function (val) {
  if (typeof val !== 'string') {
    return throwTypeError('String', 'Example.js', 'myFunc', val);
  }

  // ...
};

myFunc(1);
// Throws a Error:
// 'TypeError [ERR_INVALID_ARG_TYPE]: The argument must be one of type String
//    at myFunc (Example.js)
//    value: 1'
Parameters:
Name Type Description
trueType string

The type of expected.

moduleTitle string

The module name where the error occurred.

functionName string

The function name where the error occurred.

errVal any

The value that caused the error.

Throws:
Error

(static) throwValueError(argName, moduleTitle, functionName, errVal)

Source:

Throws an Error that caused by an invalid value of argument.

Example
var throwValueError = Wsh.Util.throwValueError; // Shorthand

var myFunc = function (val) {
  if (!val) return throwValueError('val', 'Example.js', 'myFunc', val);
  // ...
};

myFunc('');
// Throws a Error:
// 'TypeError [ERR_INVALID_ARG_VALUE]: The argument `val` cannot be ""
//    at myFunc (Example.js)'
Parameters:
Name Type Description
argName string

An argument name

moduleTitle string

The module name where the error occurred.

functionName string

The function name where the error occurred.

errVal any

The value that caused the error.

Throws:
  • Throws an Error with the invalid value message.
Type
Error

(static) toDoubleByteEN(str) → {string}

Source:

半角英数字文字列を全角文字列に変換する

Example
var toDoubleByteEN = Wsh.Util.toDoubleByteEN; // Shorthand

toDoubleByteEN('0123456789');
// Returns: '0123456789'

toDoubleByteEN('abcdefghijklmnopqrstuvwxyz');
// Returns: 'abcdefghijklmnopqrstuvwxyz'

toDoubleByteEN('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~');
// Returns: '!”#$%&’()*+,-./:;<=>?@[¥]^_‘{|} ̄'
Parameters:
Name Type Description
str string

The string to convert.

Returns:
Type
string

(static) toHalfWidthEN(str) → {string}

Source:

全角英数字文字列を半角文字列に変換する

Example
var toHalfWidthEN = Wsh.Util.toHalfWidthEN; // Shorthand

toHalfWidthEN('0123456789');
// Returns: '0123456789'

toHalfWidthEN('abcdefghijklmnopqrstuvwxyz');
// Returns: 'abcdefghijklmnopqrstuvwxyz'

toHalfWidthEN('!”#$%&’()*+,-./:;<=>?@[¥]^_‘{|} ̄');
// Returns: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
Parameters:
Name Type Description
str string

The string to convert.

Returns:
  • The converted string.
Type
string

(static) toPlainString(val) → {string}

Source:

Converts a value to a String.

Example
var toPlainString = Wsh.Util.toPlainString; // Shorthand

toPlainString(undefined); // ''
toPlainString(null); // ''
toPlainString(true); // 'true'
toPlainString(false); // 'false'
toPlainString(NaN); // 'NaN'
toPlainString(Infinity); // 'Infinity'
toPlainString('Hello world!'); // 'Hello world!'
toPlainString('  '); // '  '
toPlainString([1, NaN, '3']); // '1,NaN,3'
toPlainString([1, [2, [3]], 4]); // '1,2,3,4'
toPlainString({ a: 'A', b: { c: 'BC' } }); // 'ABC'
Parameters:
Name Type Description
val any

The value to convert.

Returns:
  • A Coverted string
Type
string

(static) toRegExpStr(str) → {string}

Source:

[W.I.P] Insert back-slashs to a string for RegExp. I was tired to escape RegExp chars.

Parameters:
Name Type Description
str string

The string to convert.

Returns:
Type
string

(static) toZenkakuKana(str) → {string}

Source:

半角カナを全角に変換する

Example
var toZenkakuKana = Wsh.Util.toZenkakuKana; // Shorthand

toZenkakuKana('ガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポヴヷヺアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンァィゥェォッャュョ。、ー「」・');
// Returns: 'ガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポヴヷヺアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンァィゥェォッャュョ。、ー「」・'
Parameters:
Name Type Description
str string

The string to convert.

Returns:
Type
string

(static) unset(obj, propPath) → {boolean}

Source:

Removes the property ato path of object.

Example
var unset = Wsh.Util.unset; // Shorthand

var obj = { a: 1, b: { B: 2 } };
unset(obj, 'a'); // obj is { b: { B: 2 } }
unset(obj, 'b.B'); // obj is { b: {} }
unset(obj, 'b'); // obj is {}

var obj = { a: 1, b: [{ B: 2 }, { C: 3 }] };
unset(objMock, ['b', 1, 'C']); // obj is { a: 1, b: [{ B: 2 }, {}] }
unset(objMock, 'b.0'); // obj is { a: 1, b: [undefined, {}] }
Parameters:
Name Type Description
obj object

The object to query.

propPath Array.<string> | string

The path of the property to get.

Returns:

Returns true if the property is deleted, else false.

Type
boolean

(static) uuidv4() → {string}

Source:

Generates a unique ID (RFC4122 version 4).

Example
var uuidv4 = Wsh.Util.uuidv4; // Shorthand

console.log(uuidv4()); // 9f1e53ba-3f08-4c9d-91c7-ad4226312f40
console.log(uuidv4()); // 50b1f801-15b6-42f3-afb2-093142cb07b7
console.log(uuidv4()); // 3a1d4289-6e78-4873-b63a-4a66a22a46ee
console.log(uuidv4()); // 5db0936a-e3ef-456f-8666-e3d2d9b087aa
console.log(uuidv4()); // f7184766-168b-4fcb-8250-11b1b6c788ec
console.log(uuidv4()); // f7c97128-938c-4ca7-b726-c07b2193a447
Returns:
  • Returns a unique ID (RFC4122 version 4).
Type
string

(static) vbsTypeOf(val) → {string}

Source:

Returns a VBS type of a value using TypeName Function. @FIXME ScriptControl does not work on Windows 64bit

Parameters:
Name Type Description
val string
Returns:
  • VBScript TypeName
Type
string