本文整理匯總了TypeScript中vs/base/common/types.isArray函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isArray函數的具體用法?TypeScript isArray怎麽用?TypeScript isArray使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isArray函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: _cloneAndChange
function _cloneAndChange(obj: any, changer: (orig: any) => any, encounteredObjects: any[]): any {
if (isUndefinedOrNull(obj)) {
return obj;
}
const changed = changer(obj);
if (typeof changed !== 'undefined') {
return changed;
}
if (isArray(obj)) {
const r1: any[] = [];
for (let i1 = 0; i1 < obj.length; i1++) {
r1.push(_cloneAndChange(obj[i1], changer, encounteredObjects));
}
return r1;
}
if (isObject(obj)) {
if (encounteredObjects.indexOf(obj) >= 0) {
throw new Error('Cannot clone recursive data-structure');
}
encounteredObjects.push(obj);
const r2 = {};
for (let i2 in obj) {
if (_hasOwnProperty.call(obj, i2)) {
(r2 as any)[i2] = _cloneAndChange(obj[i2], changer, encounteredObjects);
}
}
encounteredObjects.pop();
return r2;
}
return obj;
}
示例2: _cloneAndChange
function _cloneAndChange(obj: any, changer: (orig: any) => any, seen: Set<any>): any {
if (isUndefinedOrNull(obj)) {
return obj;
}
const changed = changer(obj);
if (typeof changed !== 'undefined') {
return changed;
}
if (isArray(obj)) {
const r1: any[] = [];
for (const e of obj) {
r1.push(_cloneAndChange(e, changer, seen));
}
return r1;
}
if (isObject(obj)) {
if (seen.has(obj)) {
throw new Error('Cannot clone recursive data-structure');
}
seen.add(obj);
const r2 = {};
for (let i2 in obj) {
if (_hasOwnProperty.call(obj, i2)) {
(r2 as any)[i2] = _cloneAndChange(obj[i2], changer, seen);
}
}
seen.delete(obj);
return r2;
}
return obj;
}
示例3: test
test('Properties', function () {
const d = new Date().getTime();
let s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
assert.strictEqual(s.isDirectoryResolved, false);
assert.strictEqual(s.resource.fsPath, toResource('/path/to/stat').fsPath);
assert.strictEqual(s.name, 'sName');
assert.strictEqual(s.isDirectory, true);
assert.strictEqual(s.mtime, new Date(d).getTime());
assert(isArray(s.children) && s.children.length === 0);
s = createStat('/path/to/stat', 'sName', false, false, 8096, d);
assert(isUndefinedOrNull(s.children));
});
示例4: test
test("Properties", function() {
let d = new Date().getTime();
let s = createStat("/path/to/stat", "sName", true, true, 8096, d);
assert.strictEqual(s.isDirectoryResolved, false);
assert.strictEqual(s.resource.fsPath, toResource("/path/to/stat").fsPath);
assert.strictEqual(s.name, "sName");
assert.strictEqual(s.isDirectory, true);
assert.strictEqual(s.hasChildren, true);
assert.strictEqual(s.mtime, new Date(d).getTime());
assert(isArray(s.children) && s.children.length === 0);
s = createStat("/path/to/stat", "sName", false, false, 8096, d);
assert(isUndefinedOrNull(s.children));
});
示例5: test
test('isArray', () => {
assert(!types.isArray(undefined));
assert(!types.isArray(null));
assert(!types.isArray('foo'));
assert(!types.isArray(5));
assert(!types.isArray(true));
assert(!types.isArray({}));
assert(!types.isArray(/test/));
assert(!types.isArray(new RegExp('')));
assert(!types.isArray(new Date()));
assert(!types.isArray(assert));
assert(!types.isArray(function foo() { /**/ }));
assert(!types.isArray({ foo: 'bar' }));
assert(types.isArray([]));
assert(types.isArray([1, 2, '3']));
});