本文整理匯總了TypeScript中vs/base/common/objects.safeStringify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript safeStringify函數的具體用法?TypeScript safeStringify怎麽用?TypeScript safeStringify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了safeStringify函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: _flaten
private static _flaten(obj: any, result: {[key: string]: any }, order: number = 0, prefix?: string): void {
if (!obj) {
return;
}
for(var item of Object.getOwnPropertyNames(obj)){
const value = obj[item];
const index = prefix ? prefix + item : item;
if (Array.isArray(value)) {
result[index] = safeStringify(value);
} else if (value instanceof Date) {
// TODO unsure why this is here and not in _getData
result[index] = value.toISOString();
} else if (isObject(value)) {
if (order < 2) {
AIAdapter._flaten(value, result, order + 1, index + '.');
} else {
result[index] = safeStringify(value);
}
} else {
result[index] = value;
}
}
}
示例2: test
test('safeStringify', function () {
let obj1: any = {
friend: null
};
let obj2: any = {
friend: null
};
obj1.friend = obj2;
obj2.friend = obj1;
let arr: any = [1];
arr.push(arr);
let circular: any = {
a: 42,
b: null,
c: [
obj1, obj2
],
d: null
};
arr.push(circular);
circular.b = circular;
circular.d = arr;
let result = objects.safeStringify(circular);
assert.deepEqual(JSON.parse(result), {
a: 42,
b: '[Circular]',
c: [
{
friend: {
friend: '[Circular]'
}
},
'[Circular]'
],
d: [1, '[Circular]', '[Circular]']
});
});