本文整理匯總了TypeScript中require.has函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript has函數的具體用法?TypeScript has怎麽用?TypeScript has使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了has函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: compile
/**
Uses HTMLBars `compile` function to process a string into a compiled template.
This is not present in production builds.
@private
@method compile
@param {String} templateString This is the string to be compiled by HTMLBars.
@param {Object} options This is an options hash to augment the compiler options.
*/
export default function compile(templateString: string, options: CompileOptions) {
if (!template && has('@ember/-internals/glimmer')) {
// tslint:disable-next-line:no-require-imports
template = require('@ember/-internals/glimmer').template;
}
if (!template) {
throw new Error(
'Cannot call `compile` with only the template compiler loaded. Please load `ember.debug.js` or `ember.prod.js` prior to calling `compile`.'
);
}
let precompiledTemplateString = precompile(templateString, options);
let templateJS = new Function(`return ${precompiledTemplateString}`)();
return template(templateJS);
}
示例2: require
import require, { has } from 'require';
type MaybeFetch = {
(input: RequestInfo, init?: RequestInit | undefined): Promise<Response>;
} | null;
let _fetch: MaybeFetch = null;
if (has('fetch')) {
// use `fetch` module by default, this is commonly provided by ember-fetch
_fetch = require('fetch').default;
} else if (typeof fetch === 'function') {
// fallback to using global fetch
_fetch = fetch;
}
export default _fetch;
示例3: require
import require, { has } from 'require';
import bootstrap from './bootstrap';
// Globals mode template compiler
if (has('@ember/application') && has('ember-browser-environment') && has('ember-glimmer')) {
// tslint:disable:no-require-imports
let emberEnv = require('ember-browser-environment');
let emberGlimmer = require('ember-glimmer');
let emberApp = require('@ember/application');
let Application = emberApp.default;
let { hasTemplate, setTemplate } = emberGlimmer;
let { hasDOM } = emberEnv;
Application.initializer({
name: 'domTemplates',
initialize() {
let context;
if (hasDOM) {
context = document;
}
bootstrap({ context, hasTemplate, setTemplate });
},
});
}
示例4: has
import require, { has } from 'require';
import bootstrap from './bootstrap';
// Globals mode template compiler
if (
has('@ember/application') &&
has('@ember/-internals/browser-environment') &&
has('@ember/-internals/glimmer')
) {
// tslint:disable:no-require-imports
let emberEnv = require('@ember/-internals/browser-environment');
let emberGlimmer = require('@ember/-internals/glimmer');
let emberApp = require('@ember/application');
let Application = emberApp.default;
let { hasTemplate, setTemplate } = emberGlimmer;
let { hasDOM } = emberEnv;
Application.initializer({
name: 'domTemplates',
initialize() {
let context;
if (hasDOM) {
context = document;
}
bootstrap({ context, hasTemplate, setTemplate });
},
});
}