本文整理匯總了TypeScript中undefined.hasOwnProperty函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript hasOwnProperty函數的具體用法?TypeScript hasOwnProperty怎麽用?TypeScript hasOwnProperty使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了hasOwnProperty函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: parse
export function parse (): Config {
try {
const packageJson = require(`${process.cwd()}/package.json`)
if (packageJson.hasOwnProperty('graphql')) {
return parseConfigJson(packageJson.graphql)
}
} catch (ex) {
// do nothing here
}
try {
const graphqlrc = JSON.parse(readFileSync(`${process.cwd()}/.graphqlrc`, 'utf-8'))
return parseConfigJson(graphqlrc)
} catch (ex) {
// do nothing here
}
if (process.env.hasOwnProperty('GRAPHQL_ENDPOINT')) {
const endpoint = process.env.GRAPHQL_ENDPOINT
if (!isWebUri(endpoint)) {
throw new Error(`No valid GraphQL endpoint: ${endpoint}`)
}
return {
url: endpoint,
type: 'request',
} as ConfigRequest
}
throw new Error('Couldn\'t find a GraphQL config. Please refer to https://github.com/graphcool/graphql-config')
}
示例2: require
.flatMap((modelSchema) => {
let schema = require(modelSchema), loader;
if (schema.hasOwnProperty('mongodb')) {
loader = mongoDbAttached(app, schema, configs);
} else {
loader = defaultAttached(app, schema, configs);
}
return loader;
});
示例3: assert
lines.forEach(line => {
if (line.search(/Get-VstsLocString/i) > 0) {
var result = /Get-VstsLocString +-Key +('[^']+'|"[^"]+"|[^ )]+)/i.exec(line);
if (!result) {
assert(false, 'Bad format string in file ' + psFile + ' on line: ' + line);
}
var key = result[1].replace(/['"]/g, "");
assert(
obj.hasOwnProperty('messages') && obj.messages.hasOwnProperty(key),
"Loc resource key not found in task.json/module.json. Resource key: '" + key + "', PS file: '" + psFile + "', JSON file: '" + jsonFile + "'.");
}
});
示例4: addRoutes
function addRoutes(base: 'protected'|'unprotected') {
const routes = getRouteModuleNames(path.resolve(__dirname, base));
for (const routeModuleName of routes) {
const routeModule = require(`./${base}/${routeModuleName}`);
for (const routeKey in routeModule) {
if (!routeModule.hasOwnProperty(routeKey)) continue;
const route: Router = routeModule[routeKey];
if (base === 'protected')
router.use(`/api/${routeModuleName}`, jwt, route.routes(), route.allowedMethods());
else
router.use(`/api/${routeModuleName}`, route.routes(), route.allowedMethods());
}
}
}
示例5: it
it('Find invalid message key in task.json', (done) => {
this.timeout(1000);
var tasksRootFolder = path.resolve(__dirname, '../../../Tasks');
var jsons: string[] = [];
fs.readdirSync(tasksRootFolder).forEach(folderName=> {
if(fs.statSync(path.join(tasksRootFolder, folderName)).isDirectory()) {
jsons.push(path.join(tasksRootFolder, folderName, "task.json"));
}
})
// The Common folder does not get copied under _build so scan the source folder instead.
var commonFolder = path.resolve(__dirname, "../../../../Tasks/Common");
fs.readdirSync(commonFolder).forEach(folderName => {
var moduleFolder = path.join(commonFolder, folderName);
var moduleJson = path.join(moduleFolder, "module.json");
if (fs.statSync(moduleFolder).isDirectory() && fs.existsSync(moduleJson)) {
jsons.push(moduleJson);
}
})
for(var i = 0; i < jsons.length; i++) {
var json = jsons[i];
var obj = require(json);
if(obj.hasOwnProperty('messages')) {
for(var key in obj.messages) {
var jsonName = path.relative(tasksRootFolder, json);
assert(key.search(/\W+/gi) < 0, ('(' + jsonName +')' + 'messages key: \'' + key +'\' contain non-word characters, only allows [a-zA-Z0-9_].'));
if(typeof(obj.messages[key]) === 'object') {
assert(obj.messages[key].loc, ('(' + jsonName +')' + 'messages key: \'' + key +'\' should have a loc string.'));
assert(obj.messages[key].loc.toString().length >= 0, ('(' + jsonName +')' + 'messages key: \'' + key +'\' should have a loc string.'));
assert(obj.messages[key].fallback, ('(' + jsonName +')' + 'messages key: \'' + key +'\' should have a fallback string.'));
assert(obj.messages[key].fallback.toString().length > 0, ('(' + jsonName +')' + 'messages key: \'' + key +'\' should have a fallback string.'));
}
else if(typeof(obj.messages[key]) === 'string') {
assert(obj.messages[key].toString().length > 0, ('(' + jsonName +')' + 'messages key: \'' + key +'\' should have a loc string.'));
}
}
}
}
done();
})
示例6: it
it('validate loc string key in lib.json', function (done) {
this.timeout(1000);
var jsonPath = path.join(__dirname, '../lib.json');
var json = require(jsonPath);
if (json && json.hasOwnProperty('messages')) {
for (var key in json.messages) {
assert(key.search(/\W+/gi) < 0, ('messages key: \'' + key + '\' contain non-word characters, only allows [a-zA-Z0-9_].'));
assert(key.search(/^LIB_/) === 0, ('messages key: \'' + key + '\' should start with \'LIB_\'.'));
if (typeof (json.messages[key]) === 'object') {
assert(false, ('messages key: \'' + key + '\' should have a loc string, not a object.'));
}
else if (typeof (json.messages[key]) === 'string') {
assert(json.messages[key].toString().length > 0, ('messages key: \'' + key + '\' should have a loc string.'));
}
}
}
done();
})
示例7: overrideSysDefaults
overrideSysDefaults(ts_impl: typeof ts, state: TypeScriptPluginState, serverFile: string) {
const path = require('path');
let tsPath = path.join(state.serverFolderPath, 'typescript.js');
try {
let fullTypescriptVersion = require(tsPath);
for (let prop in fullTypescriptVersion) {
if (fullTypescriptVersion.hasOwnProperty(prop)) {
ts_impl[prop] = fullTypescriptVersion[prop];
}
}
ts_impl["ide_processed"] = true;
//clean resources
let name = require.resolve(tsPath);
delete require.cache[name];
} catch (err) {
//do nothing
}
super.overrideSysDefaults(ts_impl, state, serverFile);
}
示例8: databaseUrl
player: {
username: string,
password: string
}
database: {
host: string,
port: number,
schema: string,
username: string,
password: string
}
get databaseUrl(): string {
return "mongodb://" + this.database.username + ":" + this.database.password + "@" + this.database.host + ":" + this.database.port + "/" + this.database.schema;
}
}
export var configuration: Configuration = new Configuration();
var configurationFile = DEFAULT_CONFIGURATION_FILE;
var configurationJson: {} = require(configurationFile);
for (var key in configurationJson) {
if (!configurationJson.hasOwnProperty(key)) {
continue;
}
configuration[key] = configurationJson[key];
}