本文整理匯總了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");
}