• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript is.object函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中is.object函数的典型用法代码示例。如果您正苦于以下问题:TypeScript object函数的具体用法?TypeScript object怎么用?TypeScript object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了object函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: BigQueryDatetime

(BigQuery as any).datetime = BigQuery.prototype.datetime = function BigQueryDatetime(
  value
) {
  if (!(this instanceof (BigQuery as any).datetime)) {
    return new (BigQuery as any).datetime(value);
  }

  if (is.object(value)) {
    let time;

    if (value.hours) {
      time = (BigQuery as any).time(value).value;
    }

    value = format('{y}-{m}-{d}{time}', {
      y: value.year,
      m: value.month,
      d: value.day,
      time: time ? ' ' + time : '',
    });
  } else {
    value = value.replace(/^(.*)T(.*)Z$/, '$1 $2');
  }

  this.value = value;
};
开发者ID:brgmn,项目名称:nodejs-bigquery,代码行数:26,代码来源:index.ts


示例2: BigQueryDate

(BigQuery as any).date = BigQuery.prototype.date = function BigQueryDate(value) {
  if (!(this instanceof (BigQuery as any).date)) {
    return new (BigQuery as any).date(value);
  }

  if (is.object(value)) {
    value = (BigQuery as any).datetime(value).value;
  }

  this.value = value;
};
开发者ID:brgmn,项目名称:nodejs-bigquery,代码行数:11,代码来源:index.ts


示例3: function

(BigQuery as any).getType_ = function(value) {
  let typeName;

  if (value instanceof (BigQuery as any).date) {
    typeName = 'DATE';
  } else if (value instanceof (BigQuery as any).datetime) {
    typeName = 'DATETIME';
  } else if (value instanceof (BigQuery as any).time) {
    typeName = 'TIME';
  } else if (value instanceof (BigQuery as any).timestamp) {
    typeName = 'TIMESTAMP';
  } else if (value instanceof Buffer) {
    typeName = 'BYTES';
  } else if (value instanceof Big) {
    typeName = 'NUMERIC';
  } else if (is.array(value)) {
    return {
      type: 'ARRAY',
      arrayType: (BigQuery as any).getType_(value[0]),
    };
  } else if (is.bool(value)) {
    typeName = 'BOOL';
  } else if (is.number(value)) {
    typeName = value % 1 === 0 ? 'INT64' : 'FLOAT64';
  } else if (is.object(value)) {
    return {
      type: 'STRUCT',
      structTypes: Object.keys(value).map(function(prop) {
        return {
          name: prop,
          type: (BigQuery as any).getType_(value[prop]),
        };
      }),
    };
  } else if (is.string(value)) {
    typeName = 'STRING';
  }

  if (!typeName) {
    throw new Error(
      [
        'This value could not be translated to a BigQuery data type.',
        value,
      ].join('\n')
    );
  }

  return {
    type: typeName,
  };
};
开发者ID:brgmn,项目名称:nodejs-bigquery,代码行数:51,代码来源:index.ts


示例4: BigQueryTime

(BigQuery as any).time = BigQuery.prototype.time = function BigQueryTime(value) {
  if (!(this instanceof (BigQuery as any).time)) {
    return new (BigQuery as any).time(value);
  }

  if (is.object(value)) {
    value = format('{h}:{m}:{s}{f}', {
      h: value.hours,
      m: value.minutes || 0,
      s: value.seconds || 0,
      f: is.defined(value.fractional) ? '.' + value.fractional : '',
    });
  }

  this.value = value;
};
开发者ID:brgmn,项目名称:nodejs-bigquery,代码行数:16,代码来源:index.ts


示例5: default

export default ({ gstore }: Context, { blog }: Modules): AdminRoutesHandlers => {
  const { blogPostDomain } = blog.blogPost;
  const { protectedBlogPosts } = blogPostDomain;

  return {
    async dashboard(req, res) {
      const template = 'admin/dashboard';

      let posts;
      try {
        posts = await blogPostDomain.getPosts({
          cache: req.query.cache !== 'false',
        });
      } catch (error) {
        return res.render(template, {
          error,
          pageId: 'admin-index',
        });
      }

      res.render(template, {
        posts: posts.entities,
        pageId: 'admin-index',
        protectedBlogPosts: protectedBlogPosts.join(','),
      });
    },
    async createPost(req, res) {
      const template = 'admin/edit';
      const dataloader = gstore.createDataLoader();

      if (req.method === 'POST') {
        const entityData = Object.assign({}, req.body, { file: req.file });

        try {
          await blogPostDomain.createPost(entityData, dataloader);
        } catch (err) {
          return res.render(template, {
            blogPost: entityData,
            error: is.object(err.message) ? err.message : err,
          });
        }

        return res.redirect('/admin?cache=false');
      }

      return res.render(template, {
        pageId: 'blogpost-edit',
      });
    },
    async editPost(req, res) {
      const template = 'admin/edit';
      const pageId = 'blogpost-edit';
      const dataloader = gstore.createDataLoader();
      const { id } = req.params;

      if (req.method === 'POST') {
        const entityData = Object.assign({}, req.body, { file: req.file });

        try {
          await blogPostDomain.updatePost(id, entityData, dataloader, true);
        } catch (err) {
          return res.render(template, {
            post: Object.assign({}, entityData, { id }),
            pageId,
            error: is.object(err.message) ? err.message : err,
            protectedBlogPosts: protectedBlogPosts.join(','),
          });
        }

        return res.redirect('/admin?cache=false');
      }

      let post;
      try {
        post = await blogPostDomain.getPost(id, dataloader);
      } catch (err) {
        return res.render(template, {
          post: {},
          pageId,
          error: is.object(err.message) ? err.message : err,
          protectedBlogPosts: protectedBlogPosts.join(','),
        });
      }

      if (!post) {
        return res.redirect('/404');
      }

      res.render(template, {
        post,
        pageId,
        protectedBlogPosts: protectedBlogPosts.join(','),
      });
    },
  };
};
开发者ID:sebelga,项目名称:blog-app-googlecloud,代码行数:96,代码来源:admin.routes-handlers.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript is.string函数代码示例发布时间:2022-05-25
下一篇:
TypeScript is.fn函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap