本文整理匯總了TypeScript中underscore.isString函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isString函數的具體用法?TypeScript isString怎麽用?TypeScript isString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isString函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: isInvalidQueryStringValue
private static isInvalidQueryStringValue(value: any) {
if (isString(value)) {
return Utils.isEmptyString(value);
}
return Utils.isNullOrUndefined(value);
}
示例2: createElement
export function createElement(type: string, props: { [name: string]: any },
...children: Array<string | HTMLElement | Array<string | HTMLElement>>): HTMLElement {
let elem;
if (type === "fragment") {
elem = document.createDocumentFragment();
} else {
elem = document.createElement(type);
for (let k in props) {
let v = props[k];
if (k === "className")
k = "class";
if (k === "class" && isArray(v))
v = v.filter(c => c != null).join(" ");
if (v == null || isBoolean(v) && !v)
continue
elem.setAttribute(k, v);
}
}
for (const v of flatten(children, true)) {
if (v instanceof HTMLElement)
elem.appendChild(v);
else if (isString(v))
elem.appendChild(document.createTextNode(v))
}
return elem;
}
示例3: detectFloat
this.forEach((el: any) => {
// console.log('getRowTypes', el);
// let float = parseFloat(el); // does not handle 1.000,12 well
let float = detectFloat(el);
let date = Date.parse(el);
let isDate = !!date && el.indexOf(',') == -1; // dates are without ","
let isEmpty = _.isNull(el)
|| _.isUndefined(el)
|| el == '';
let commas = 0;
if (_.isString(el)) {
commas = el.split(',').length - 1;
}
let elWithoutEUR = (el || '').replace('EUR', '').trim();
let onlyNumbers = /^[\-,\.\d]+$/.test(elWithoutEUR);
if (float && !isDate && commas == 1 && onlyNumbers) {
types.push('number');
} else if (isDate) {
types.push('date');
} else if (isEmpty) {
types.push('null');
} else {
types.push('string');
}
});
示例4: function
'iftype': function (val: any, type: 'array' | 'object' | 'boolean' | 'number' | 'string' | 'simple', options) {
let condition = false;
switch (type) {
case 'array':
condition = _.isArray(val)
break;
case 'object':
condition = _.isObject(val)
break;
case 'boolean':
condition = _.isBoolean(val)
break;
case 'number':
condition = _.isNumber(val)
break;
case 'string':
condition = _.isString(val)
break;
case 'simple':
condition = !(_.isObject(val) || _.isArray(val) || _.isUndefined(val));
break;
default:
condition = false;
break;
}
return Handlebars.helpers['if'].call(this, condition, options);
},
示例5: __render
// TODO: Function overloading?
__render(html, callback: RenderCallback) {
var $scope = null;
var $cheerio = $;
if (_.isString(html)) {
$scope = $.load(html)(this._documentSelector);
} else if (_.isObject(html)) {
$scope = $(html).find(this._documentSelector); // must be DOM
} else {
return callback(new Error('Must be Cheerio DOM object'), null, null);
}
if (this._documentSelectorIndex) {
try {
$scope = $($scope[this._documentSelectorIndex]);
} catch (e) {
throw new Error('No selector index at "' + this._documentSelectorIndex + '"');
}
}
// monkey patch $scope
$scope.$find = MenioModel.__find($scope);
let self = {
model: {}
};
_.extend(self, this._props);
for (let i = 0; i < this._keys.length; i++) {
let name = this._keys[i];
try {
// DI - scope, cheerio and _
let opts = this._mappings[i].call(self, $($scope), $cheerio, _);
// only call next if callback and next
if (callback && opts && opts.next) {
callback(null, opts.$scope, self.model);
return;
} else {
if (!self.model[name]) {
self.model[name] = opts;
}
}
} catch (e) {
throw e;
}
}
if (callback) {
return callback(null, null, self.model);
} else {
return self.model;
}
};
示例6: it
it('should support rendering as a simple string and not an HTML element', () => {
facet.options.title = 'My facet title';
const builtAsString = new BreadcrumbValueList(facet, facetValues, BreadcrumbValueElement).buildAsString();
expect(_.isString(builtAsString)).toBe(true);
expect(builtAsString).toContain('My facet title');
expect(builtAsString).toContain('foo0');
expect(builtAsString).toContain('foo1');
expect(builtAsString).toContain('foo2');
});
示例7: _toolbox_monitor
public static _toolbox_monitor(
subscription: ClientSubscription,
timestampsToReturn: TimestampsToReturn,
monitoredItems: ClientMonitoredItemBase[],
done: ErrorCallback
) {
assert(_.isFunction(done));
const itemsToCreate: MonitoredItemCreateRequestOptions[] = [];
for (const monitoredItem of monitoredItems) {
const monitoredItemI = monitoredItem as ClientMonitoredItemBaseImpl;
const itemToCreate = monitoredItemI._prepare_for_monitoring();
if (_.isString(itemToCreate.error)) {
return done(new Error(itemToCreate.error));
}
itemsToCreate.push(itemToCreate as MonitoredItemCreateRequestOptions);
}
const createMonitorItemsRequest = new CreateMonitoredItemsRequest({
itemsToCreate,
subscriptionId: subscription.subscriptionId,
timestampsToReturn,
});
const session = subscription.session as ClientSessionImpl;
assert(session,
"expecting a valid session attached to the subscription ");
session.createMonitoredItems(
createMonitorItemsRequest,
(err?: Error | null, response?: CreateMonitoredItemsResponse) => {
/* istanbul ignore next */
if (err) {
debugLog(chalk.red("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems "));
} else {
if (!response) {
return done(new Error("Internal Error"));
}
response.results = response.results || [];
for (let i = 0; i < response.results.length; i++) {
const monitoredItemResult = response.results[i];
const monitoredItem = monitoredItems[i] as ClientMonitoredItemBaseImpl;
monitoredItem._after_create(monitoredItemResult);
}
}
done(err ? err : undefined);
});
}
示例8: convertObjectToTsInterfaces
private convertObjectToTsInterfaces(jsonContent: any, objectName: string = "RootObject"): string {
let optionalKeys: string[] = [];
let objectResult: string[] = [];
for (let key in jsonContent) {
let value = jsonContent[key];
if (_.isObject(value) && !_.isArray(value)) {
let childObjectName = this.toUpperFirstLetter(key);
objectResult.push(this.convertObjectToTsInterfaces(value, childObjectName));
jsonContent[key] = this.removeMajority(childObjectName) + ";";
} else if (_.isArray(value)) {
let arrayTypes: any = this.detectMultiArrayTypes(value);
if (this.isMultiArray(arrayTypes)) {
let multiArrayBrackets = this.getMultiArrayBrackets(value);
if (this.isAllEqual(arrayTypes)) {
jsonContent[key] = arrayTypes[0].replace("[]", multiArrayBrackets);
} else {
jsonContent[key] = "any" + multiArrayBrackets + ";";
}
} else if (value.length > 0 && _.isObject(value[0])) {
let childObjectName = this.toUpperFirstLetter(key);
objectResult.push(this.convertObjectToTsInterfaces(value[0], childObjectName));
jsonContent[key] = this.removeMajority(childObjectName) + "[];";
} else {
jsonContent[key] = arrayTypes[0];
}
} else if (_.isDate(value)) {
jsonContent[key] = "Date;";
} else if (_.isString(value)) {
jsonContent[key] = "string;";
} else if (_.isBoolean(value)) {
jsonContent[key] = "boolean;";
} else if (_.isNumber(value)) {
jsonContent[key] = "number;";
} else {
jsonContent[key] = "any;";
optionalKeys.push(key);
}
}
let result = this.formatCharsToTypeScript(jsonContent, objectName, optionalKeys);
objectResult.push(result);
return objectResult.join("\n\n");
}
示例9: if
_.each(result.raw, (value: any, key: string) => {
let fieldDescription = fieldDescriptions['@' + key];
if (fieldDescription == null && key.match(/^sys/)) {
fieldDescription = fieldDescriptions['@' + key.substr(3)];
}
if (fieldDescription == null) {
fields['@' + key] = value;
} else if (fieldDescription.fieldType == 'Date') {
fields['@' + key] = new Date(value);
} else if (fieldDescription.splitGroupByField && _.isString(value)) {
fields['@' + key] = value.split(/\s*;\s*/);
} else {
fields['@' + key] = value;
}
});
示例10: _coerceNode
public _coerceNode(node: State | BaseNode | null | string | NodeId): BaseNode | null {
if (node === null) {
return null;
}
const addressSpace = this.addressSpace;
if (node instanceof BaseNode) {
return node;
} else if (node instanceof NodeId) {
return addressSpace.findNode(node) as BaseNode;
} else if (_.isString(node)) {
return this.getStateByName(node) as any as BaseNode;
}
return null;
}