本文整理匯總了TypeScript中ember-cli-string-utils.dasherize函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dasherize函數的具體用法?TypeScript dasherize怎麽用?TypeScript dasherize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了dasherize函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
locals: function(options: any) {
this.styleExt = options.style === 'stylus' ? 'styl' : options.style;
this.version = require(path.resolve(__dirname, '../../package.json')).version;
// set this.tests to opposite of skipTest options,
// meaning if tests are being skipped then the default.spec.BLUEPRINT will be false
this.tests = options.skipTests ? false : true;
// Split/join with / not path.sep as reference to typings require forward slashes.
const relativeRootPath = options.sourceDir.split('/').map(() => '..').join('/');
const fullAppName = (stringUtils.dasherize(options.entity.name) as string)
.replace(/-(.)/g, (_, l) => ' ' + l.toUpperCase())
.replace(/^./, (l) => l.toUpperCase());
return {
htmlComponentName: stringUtils.dasherize(options.entity.name),
jsComponentName: stringUtils.classify(options.entity.name),
fullAppName: fullAppName,
version: this.version,
sourceDir: options.sourceDir,
prefix: options.prefix,
styleExt: this.styleExt,
relativeRootPath: relativeRootPath,
routing: options.routing,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
ng4: options.ng4,
tests: this.tests
};
},
示例2: function
normalizeEntityName: function (entityName: string) {
const appConfig = getAppFromConfig(this.options.app);
const dynamicPathOptions: DynamicPathOptions = {
project: this.project,
entityName,
appConfig,
dryRun: this.options.dryRun
};
const parsedPath = dynamicPathParser(dynamicPathOptions);
this.dynamicPath = parsedPath;
const defaultPrefix = (appConfig && appConfig.prefix) || '';
let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
? '' : (this.options.prefix || defaultPrefix);
prefix = prefix && `${prefix}-`;
this.selector = stringUtils.dasherize(prefix + parsedPath.name);
if (this.selector.indexOf('-') === -1) {
this._writeStatusToUI(chalk.yellow, 'WARNING', 'selectors should contain a dash');
}
return parsedPath.name;
},
示例3: function
afterInstall: function (options: any) {
const appConfig = getAppFromConfig(this.options.app);
if (options.prefix && appConfig.prefix && appConfig.prefix !== options.prefix) {
console.log(chalk.yellow(oneLine`You are using different prefix from app,
you might get lint errors. Please update "tslint.json" accordingly.`));
}
const returns: Array<any> = [];
const className = stringUtils.classify(`${options.entity.name}Component`);
const fileName = stringUtils.dasherize(`${options.entity.name}.component`);
const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath);
const normalizeRelativeDir = componentDir.startsWith('.') ? componentDir : `./${componentDir}`;
const importPath = componentDir ? `${normalizeRelativeDir}/${fileName}` : `./${fileName}`;
if (!options.skipImport) {
if (options.dryRun) {
this._writeStatusToUI(chalk.yellow,
'update',
path.relative(this.project.root, this.pathToModule));
return;
}
let preChange: any;
try {
preChange = fs.readFileSync(this.pathToModule, 'utf8');
} catch (err) {
if (err.code === 'EISDIR') {
throw 'Module specified should be a file, not a directory';
} else {
throw err;
}
}
returns.push(
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
.then((change: any) => change.apply(NodeHost))
.then((result: any) => {
if (options.export) {
return astUtils.addExportToModule(this.pathToModule, className, importPath)
.then((change: any) => change.apply(NodeHost));
}
return result;
})
.then(() => {
const postChange = fs.readFileSync(this.pathToModule, 'utf8');
let moduleStatus = 'update';
if (postChange === preChange) {
moduleStatus = 'identical';
}
this._writeStatusToUI(chalk.yellow,
moduleStatus,
path.relative(this.project.root, this.pathToModule));
this.addModifiedFile(this.pathToModule);
}));
}
return Promise.all(returns);
}
示例4: function
afterInstall: function(options: any) {
if (options.dryRun) {
return;
}
const returns: Array<any> = [];
const className = stringUtils.classify(`${options.entity.name}Directive`);
const fileName = stringUtils.dasherize(`${options.entity.name}.directive`);
const fullGeneratePath = path.join(this.project.root, this.generatePath);
const moduleDir = path.parse(this.pathToModule).dir;
const relativeDir = path.relative(moduleDir, fullGeneratePath);
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;
if (!options.skipImport) {
returns.push(
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
.then((change: any) => change.apply(NodeHost))
.then((result: any) => {
if (options.export) {
return astUtils.addExportToModule(this.pathToModule, className, importPath)
.then((change: any) => change.apply(NodeHost));
}
return result;
}));
this._writeStatusToUI(chalk.yellow,
'update',
path.relative(this.project.root, this.pathToModule));
}
return Promise.all(returns);
}
示例5: function
run: function (commandOptions: any, rawArgs: string[]) {
if (rawArgs[0] === 'module' && !rawArgs[1]) {
throw 'The `ng generate module` command requires a name to be specified.';
}
const entityName = rawArgs[1];
commandOptions.name = stringUtils.dasherize(entityName.split(separatorRegEx).pop());
const appConfig = getAppFromConfig(commandOptions.app);
const dynamicPathOptions: DynamicPathOptions = {
project: this.project,
entityName: entityName,
appConfig: appConfig,
dryRun: commandOptions.dryRun
};
const parsedPath = dynamicPathParser(dynamicPathOptions);
const root = appConfig.root + path.sep;
commandOptions.sourceDir = appConfig.root;
commandOptions.appRoot = parsedPath.appRoot.startsWith(root)
? parsedPath.appRoot.substr(root.length)
: parsedPath.appRoot;
commandOptions.path = parsedPath.dir.replace(separatorRegEx, '/');
if (parsedPath.dir.startsWith(root)) {
commandOptions.path = commandOptions.path.substr(root.length);
}
const cwd = this.project.root;
const schematicName = rawArgs[0];
if (['component', 'c', 'directive', 'd'].indexOf(schematicName) !== -1) {
if (commandOptions.prefix === undefined) {
commandOptions.prefix = appConfig.prefix;
}
if (schematicName === 'component' || schematicName === 'c') {
if (commandOptions.styleext === undefined) {
commandOptions.styleext = CliConfig.getValue('defaults.styleExt');
}
}
}
const SchematicRunTask = require('../tasks/schematic-run').default;
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
project: this.project
});
const collectionName = this.getCollectionName(rawArgs);
if (collectionName === '@schematics/angular' && schematicName === 'interface' && rawArgs[2]) {
commandOptions.type = rawArgs[2];
}
return schematicRunTask.run({
taskOptions: commandOptions,
workingDir: cwd,
collectionName,
schematicName
});
},
示例6: function
locals: function (options: any) {
this.fileName = stringUtils.dasherize(options.entity.name);
return {
dynamicPath: this.dynamicPath.dir,
flat: options.flat,
fileName: this.fileName
};
},
示例7: function
afterInstall: function (options: any) {
const returns: Array<any> = [];
const className = stringUtils.classify(`${options.entity.name}Component`);
const fileName = stringUtils.dasherize(`${options.entity.name}.component`);
const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath);
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
if (!options.skipImport) {
if (options.dryRun) {
this._writeStatusToUI(chalk.yellow,
'update',
path.relative(this.project.root, this.pathToModule));
return;
}
let preChange: any;
try {
preChange = fs.readFileSync(this.pathToModule, 'utf8');
} catch (err) {
if (err.code === 'EISDIR') {
throw 'Module specified should be a file, not a directory';
} else {
throw err;
}
}
returns.push(
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
.then((change: any) => change.apply(NodeHost))
.then((result: any) => {
if (options.export) {
return astUtils.addExportToModule(this.pathToModule, className, importPath)
.then((change: any) => change.apply(NodeHost));
}
return result;
})
.then(() => {
const postChange = fs.readFileSync(this.pathToModule, 'utf8');
let moduleStatus = 'update';
if (postChange === preChange) {
moduleStatus = 'identical';
}
this._writeStatusToUI(chalk.yellow,
moduleStatus,
path.relative(this.project.root, this.pathToModule));
}));
}
return Promise.all(returns);
}
示例8: function
run: function (commandOptions: any, rawArgs: string[]) {
if (rawArgs[0] === 'module' && !rawArgs[1]) {
throw 'The `ng generate module` command requires a name to be specified.';
}
const entityName = rawArgs[1];
commandOptions.name = stringUtils.dasherize(entityName.split(separatorRegEx).pop());
const appConfig = getAppFromConfig(commandOptions.app);
const dynamicPathOptions: DynamicPathOptions = {
project: this.project,
entityName: entityName,
appConfig: appConfig,
dryRun: commandOptions.dryRun
};
const parsedPath = dynamicPathParser(dynamicPathOptions);
commandOptions.sourceDir = appConfig.root;
commandOptions.path = parsedPath.dir
.replace(appConfig.root + path.sep, '')
.replace(separatorRegEx, '/');
const cwd = this.project.root;
const schematicName = rawArgs[0];
const SchematicRunTask = require('../tasks/schematic-run').default;
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
project: this.project
});
const collectionName = this.getCollectionName(rawArgs);
if (collectionName === '@schematics/angular' && schematicName === 'interface' && rawArgs[2]) {
commandOptions.type = rawArgs[2];
}
return schematicRunTask.run({
taskOptions: commandOptions,
workingDir: cwd,
collectionName,
schematicName
});
},