本文整理汇总了TypeScript中underscore.string类的典型用法代码示例。如果您正苦于以下问题:TypeScript string类的具体用法?TypeScript string怎么用?TypeScript string使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了string类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findFormatter
export function findFormatter(name: string | Function, formattersDirectory?: string) {
if (isFunction(name)) {
return name;
} else if (isString(name)) {
const camelizedName = camelize(`${name}Formatter`);
// first check for core formatters
let Formatter = loadFormatter(CORE_FORMATTERS_DIRECTORY, camelizedName);
if (Formatter != null) {
return Formatter;
}
// then check for rules within the first level of rulesDirectory
if (formattersDirectory) {
Formatter = loadFormatter(formattersDirectory, camelizedName);
if (Formatter) {
return Formatter;
}
}
// else try to resolve as module
return loadFormatterModule(name);
} else {
// If an something else is passed as a name (e.g. object)
throw new Error(`Name of type ${typeof name} is not supported.`);
}
}
示例2: transformName
function transformName(name: string) {
// camelize strips out leading and trailing underscores and dashes, so make sure they aren't passed to camelize
// the regex matches the groups (leading underscores and dashes)(other characters)(trailing underscores and dashes)
const nameMatch = name.match(/^([-_]*)(.*?)([-_]*)$/);
if (nameMatch == null) {
return name + "Rule";
}
return nameMatch[1] + camelize(nameMatch[2]) + nameMatch[3] + "Rule";
}
示例3: require
_.forEach(models, (model, modelName: string) => {
let fileName: string,
resource,
router,
route;
if (!_.includes(['sequelize', 'Sequelize'], modelName)) {
fileName = _str.sprintf('./%s-rt', modelName.toLowerCase());
route = require (fileName);
resource = epilogue.resource({
model: model,
endpoints: [
_str.sprintf('/%ss', modelName.toLowerCase()),
_str.sprintf('/%ss/:id', modelName.toLowerCase())
]
});
router = route(model, resource);
app.use(_str.sprintf('/api/%ss', modelName.toLowerCase()), router);
}
});
示例4: return
return (dispatch, getState) => {
const {
edit: { article },
} = getState()
const newArticle = cloneDeep(article)
const activeSection = newArticle.sections[sectionIndex]
const isText = activeSection.type === "text"
if (!isText) {
// No action necessary if section is not text
return
} else {
const isEmptyHtml = !clean(stripTags(activeSection.body)).length
const isEmptyH1 = isEmptyHtml && activeSection.body.includes("<h1>")
if (!isEmptyHtml) {
// No action necessary if text is present
return
} else if (isEmptyH1) {
// Preserve empty H1 as section divider
newArticle.sections[sectionIndex].body = "<h1></h1>"
dispatch(onChangeArticle("sections", newArticle.sections))
} else {
// Remove text sections with empty body
dispatch(removeSection(sectionIndex))
}
}
}
示例5:
meta.extras.forEach((extra: any) => {
var extraUri = extraBaseIri + _s.dasherize(extra.key.toLowerCase());
this.addTriple(datasetUri, extraUri, `"${extra.value}"`);
this.addTriple(extraUri, ns.rdfs + 'label', `"${extra.key}"`);
if (extra.key === 'Rujukan' && _s.startsWith(extra.value, 'http')) {
this.addTriple(datasetUri, ns.rdfs + 'seeAlso', extra.value);
}
});
示例6: if
preProcessRow(rowObject: CsvRow, observationMap: ObservationMap): CsvRow {
const processedRow = {...rowObject};
this.heuristicFields.forEach(ignoredField => {
delete processedRow[ignoredField];
});
// Handle refArea
if (rowObject.kode_kabkota) {
observationMap.set(ns.bm + 'refArea', ns.bps + rowObject.kode_kabkota);
}
else if (rowObject.kode_provinsi) {
observationMap.set(ns.bm + 'refArea', ns.bps + rowObject.kode_provinsi);
}
// Handle refPeriod
if (rowObject.tahun && rowObject.bulan) {
var period = rowObject.tahun + '-' + _s.pad(rowObject.bulan, 2, '0');
observationMap.set(ns.bm + 'refPeriod', `"${period}"^^<${ns.xsd}gYearMonth>`);
}
else if (rowObject.tahun) {
if (yearRegex.test(rowObject.tahun)) {
observationMap.set(ns.bm + 'refPeriod', `"${rowObject.tahun}"^^<${ns.xsd}gYear>`);
}
else {
observationMap.set(ns.bm + 'refPeriod', `"${rowObject.tahun}"`);
}
}
return processedRow;
}
示例7: fetch
async fetch(): Promise<void> {
if (!this.fetcherParams.datasetId) {
this.error('No dataset was specified.');
return;
}
let datasetMetadata = await this.fetchCkanMetadata();
let csvUrl;
for (const resource of datasetMetadata.resources) {
if (_s.endsWith(resource.url, '.csv')) {
csvUrl = resource.url;
break;
}
}
if (csvUrl) {
this.addMetadataTriples(datasetMetadata);
let csvFetcher = this.addDependentFetcher({
name: 'csv',
fetcherClassName: 'DataGoIdCsvDatacubeFetcher',
fetcherParams: {
csvUrl: csvUrl,
datasetIri: this.datasetIri
}
});
await csvFetcher.fetch();
}
}
示例8: resetToOriginal
resetToOriginal() {
if (s.isBlank(this._originalValue())) {
this.edit();
} else {
this._value(this._originalValue());
this._canEdit(false);
}
}
示例9: return
return (_dispatch, _getState) => {
let blockquote = html
const beforeHtml = _s(html).strLeft("<blockquote>")._wrapped
const afterHtml = _s(html).strRight("</blockquote>")._wrapped
if (beforeHtml) {
// add text before blockquote to new text section
blockquote = blockquote.replace(beforeHtml, "")
}
if (afterHtml) {
// add text after blockquote to new text section
blockquote = blockquote.replace(afterHtml, "")
}
const newBlocks = {
blockquote,
beforeHtml,
afterHtml,
}
return newBlocks
}
示例10: slackFieldify
var result = _.map(_.keys(inputObj), function(key){
if (!_.isObject(inputObj[key])) {
return {
title: s(prefix + key).humanize().titleize().value(),
value: inputObj[key],
short: short
}
} else {
return slackFieldify(inputObj[key], short, prefix + key)
}
})