本文整理汇总了TypeScript中underscore.isDate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isDate函数的具体用法?TypeScript isDate怎么用?TypeScript isDate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isDate函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setTimeout
setTimeout(function () {
//check if there is something to validate -> check required data for validation
var namesAreValid = data.Deputy1 !== undefined && data.Deputy1.FirstName !== undefined && data.Deputy1.LastName !== undefined;
var datesAreValid = _.isDate(data.Duration.From) && _.isDate(data.Duration.To);
if (!namesAreValid || !datesAreValid) {
//nothing to validate
deferred.resolve(true);
return;
}
//fetch items form somewhere - eg. db
var items =
[
{ "approvedDays": [moment(), moment().add('days', 1).startOf('days')], "fullName": "John Smith" },
{ "approvedDays": [moment().add('days', 1).startOf('days'), moment().add('days', 2).startOf('days')], "fullName": "Paul Neuman" },
];
//find out range
var durationRange = moment().range(data.Duration.From, data.Duration.To);
//validation
var hasSomeConflicts = _.some(items, function (item) {
return (item.fullName == (data.Deputy1.FirstName + " " + data.Deputy1.LastName) &&
_.some(item.approvedDays, function (approvedDay) {
return durationRange.contains(approvedDay.startOf('days'));
}));
});
deferred.resolve(!hasSomeConflicts);
}, 1000);
示例2: camelifyObject
export function camelifyObject(obj: any): any {
if (obj && typeof obj === "object") {
if (Array.isArray(obj)) {
const res = Array(obj.length);
for (let i = 0; i < obj.length; i++) {
res[i] = camelifyObject(obj[i]);
}
return res;
} else if (isDate(obj)) {
return obj;
} else {
const keys = Object.keys(obj);
if (keys.length === 0) {
return obj;
}
const res: any = {};
for (const key of keys) {
res[camelify(key)] = camelifyObject(obj[key]);
}
return res;
}
} else {
return obj;
}
}
示例3: 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");
}