本文整理汇总了TypeScript中@phosphor/coreutils.JSONExt.isObject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript JSONExt.isObject方法的具体用法?TypeScript JSONExt.isObject怎么用?TypeScript JSONExt.isObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@phosphor/coreutils.JSONExt
的用法示例。
在下文中一共展示了JSONExt.isObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getOption
export function getOption(name: string): string {
if (configData) {
return configData[name] || Private.getBodyData(name);
}
configData = Object.create(null);
let found = false;
// Use script tag if available.
if (typeof document !== 'undefined') {
const el = document.getElementById('jupyter-config-data');
if (el) {
configData = JSON.parse(el.textContent || '') as {
[key: string]: string;
};
found = true;
}
}
// Otherwise use CLI if given.
if (!found && typeof process !== 'undefined') {
try {
const cli = minimist(process.argv.slice(2));
const path: any = require('path');
let fullPath = '';
if ('jupyter-config-data' in cli) {
fullPath = path.resolve(cli['jupyter-config-data']);
} else if ('JUPYTER_CONFIG_DATA' in process.env) {
fullPath = path.resolve(process.env['JUPYTER_CONFIG_DATA']);
}
if (fullPath) {
/* tslint:disable */
// Force Webpack to ignore this require.
configData = eval('require')(fullPath) as { [key: string]: string };
/* tslint:enable */
}
} catch (e) {
console.error(e);
}
}
if (!JSONExt.isObject(configData)) {
configData = Object.create(null);
} else {
for (let key in configData) {
// Quote characters are escaped, unescape them.
configData[key] = String(configData[key])
.split(''')
.join('"');
}
}
return configData![name] || Private.getBodyData(name);
}
示例2: getOption
function getOption(name: string): string {
if (configData) {
return configData[name] || '';
}
configData = Object.create(null);
let found = false;
// Use script tag if available.
if (typeof document !== 'undefined') {
let el = document.getElementById('jupyter-config-data');
if (el) {
configData = JSON.parse(el.textContent || '') as { [key: string]: string };
console.log('\n\n\n******ho');
found = true;
}
}
// Otherwise use CLI if given.
if (!found && typeof process !== 'undefined') {
try {
let cli = minimist(process.argv.slice(2));
if ('jupyter-config-data' in cli) {
let path: any = require('path');
let fullPath = path.resolve(cli['jupyter-config-data']);
// Force Webpack to ignore this require.
configData = eval('require')(fullPath) as { [key: string]: string };
}
} catch (e) {
console.error(e);
}
}
if (!JSONExt.isObject(configData)) {
configData = Object.create(null);
} else {
for (let key in configData) {
configData[key] = String(configData[key]);
}
}
console.log('\n\n\n******');
console.log(JSON.stringify(configData, null, 2));
return configData[name] || '';
}
示例3: validateMimeValue
export function validateMimeValue(
type: string,
value: MultilineString | JSONObject
): boolean {
// Check if "application/json" or "application/foo+json"
const jsonTest = /^application\/(.*?)+\+json$/;
const isJSONType = type === 'application/json' || jsonTest.test(type);
let isString = (x: any) => {
return Object.prototype.toString.call(x) === '[object String]';
};
// If it is an array, make sure if is not a JSON type and it is an
// array of strings.
if (Array.isArray(value)) {
if (isJSONType) {
return false;
}
let valid = true;
(value as string[]).forEach(v => {
if (!isString(v)) {
valid = false;
}
});
return valid;
}
// If it is a string, make sure we are not a JSON type.
if (isString(value)) {
return !isJSONType;
}
// It is not a string, make sure it is a JSON type.
if (!isJSONType) {
return false;
}
// It is a JSON type, make sure it is a valid JSON object.
return JSONExt.isObject(value);
}
示例4: it
it('should test whether a JSON value is an object', () => {
expect(JSONExt.isObject({ a: 1 })).to.equal(true);
expect(JSONExt.isObject({})).to.equal(true);
expect(JSONExt.isObject([])).to.equal(false);
expect(JSONExt.isObject(1)).to.equal(false);
});