当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript underscore.isDate函数代码示例

本文整理汇总了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);
开发者ID:rsamec,项目名称:business-rules,代码行数:30,代码来源:FakeVacationDeputyService.ts

示例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;
  }
}
开发者ID:HorrerGames,项目名称:itch,代码行数:26,代码来源:camelify.ts

示例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");
    }
开发者ID:lafe,项目名称:VSCode-json2ts,代码行数:49,代码来源:Json2Ts.ts


注:本文中的underscore.isDate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。