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


TypeScript tools.is类代码示例

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


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

示例1: source

/**
 * Retrieve, parse and display a map source.
 */
async function source(req: Request, res: Response) {
   const key: string = req.params[RouteParam.MapSource];

   if (!is.text(key)) {
      return view.notFound(req, res);
   }

   const geo = await loadSource(key.replace('.json', ''));

   if (!is.value<MapSource>(geo)) {
      return view.notFound(req, res);
   }

   const geoText = JSON.stringify(geo);

   try {
      compress.gzip(Buffer.from(geoText), (err: Error, buffer: Buffer) => {
         if (is.value(err)) {
            view.internalError(res, err);
         } else {
            res.setHeader(Header.Content.Encoding, Encoding.GZip);
            res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
            res.setHeader(Header.Content.Type, addCharSet(MimeType.JSON));
            res.setHeader(
               Header.Content.Disposition,
               `attachment; filename=${key}`
            );
            res.write(buffer);
            res.end();
         }
      });
   } catch (err) {
      view.internalError(res, err);
   }
}
开发者ID:Trail-Image,项目名称:blog,代码行数:38,代码来源:map.ts

示例2: normalizeTag

export function normalizeTag(slug: string): string {
   if (is.value(slug)) {
      slug = slug.toLowerCase();
   } else {
      return null;
   }
   return is.defined(config.photoTagChanges, slug)
      ? config.photoTagChanges[slug]
      : slug;
}
开发者ID:Trail-Image,项目名称:blog,代码行数:10,代码来源:photo.ts

示例3: internalError

/**
 * Render status `500` page.
 */
function internalError(res: Response, err?: Error): void {
   if (is.value(err)) {
      log.error(err);
   }
   res.statusCode = HttpStatus.InternalError;
   res.render(Page.InternalError, { title: 'Oops', config });
}
开发者ID:Trail-Image,项目名称:blog,代码行数:10,代码来源:view.ts

示例4: list

export function list(req: Request, res: Response) {
   const key = req.params[RouteParam.RootCategory] as string;

   if (is.empty(key)) {
      return view.notFound(req, res);
   }

   view.send(res, key, render => {
      // use renderer to build view that wasn't cached
      const category = blog.categoryWithKey(key);

      if (!is.value(category)) {
         return view.notFound(req, res);
      }

      render(
         Page.CategoryList,
         standardContext(category, category.subcategories.size, {
            jsonLD: category.jsonLD(),
            subtitle: 'Subcategories',
            subcategories: Array.from(category.subcategories)
         })
      );
   });
}
开发者ID:Trail-Image,项目名称:blog,代码行数:25,代码来源:category.ts

示例5: tags

function tags(req: Request, res: Response) {
   let slug = tagParam(req);
   const list = blog.tags;
   const keys = Array.from(list.keys());
   const tags: { [key: string]: { [key: string]: string } } = {};

   if (is.empty(slug)) {
      // select a random tag
      slug = keys[Math.floor(Math.random() * keys.length + 1)];
   }

   // group tags by first letter (character)
   for (const c of alphabet) {
      tags[c] = {};
   }
   for (const [key, value] of list.entries()) {
      // key is sometimes a number
      const c = (key.toString()).substr(0, 1).toLowerCase();
      if (alphabet.indexOf(c) >= 0) {
         // ignore tags that don't start with a letter of the alphabet
         tags[c][key] = value;
      }
   }

   res.render(Page.PhotoTag, {
      tags,
      selected: slug,
      alphabet,
      title: keys.length + ' Photo Tags',
      config
   });
}
开发者ID:Trail-Image,项目名称:blog,代码行数:32,代码来源:photo.ts

示例6: story

export function story(text: string): string {
   if (is.empty(text)) {
      return text;
   }

   if (re.poetry.all.test(text)) {
      // text is entirely a poem or haiku
      text = text.replace(re.poetry.delimiter, '');

      if (re.haiku.all.test(text)) {
         // haiku
         text = formatHaiku(text, re.haiku.all);
      } else {
         // not hiaku
         text =
            '<p class="poem">' +
            text
               .replace(re.lineBreak, '<br/>')
               .replace(re.poetry.indent, '<span class="tab"></span>') +
            '</p>';
      }
   } else if (re.haiku.any.test(text)) {
      // text begins with a haiku
      text = formatHaiku(text, re.haiku.any);
   } else {
      // text has no haiku but may be partially a poem
      text = caption(text);
   }

   return text;
}
开发者ID:Trail-Image,项目名称:blog,代码行数:31,代码来源:html.ts

示例7: reject

   new Promise<ViewItem>((resolve, reject) => {
      let text: string;
      let inferredType: MimeType;

      if (is.text(htmlOrJSON)) {
         text = htmlOrJSON;
         inferredType = MimeType.HTML;
      } else {
         text = JSON.stringify(htmlOrJSON);
         inferredType = MimeType.JSON;
      }
      if (type === undefined) {
         type = inferredType;
      }

      compress.gzip(Buffer.from(text), (err: Error, buffer: Buffer) => {
         if (is.value(err)) {
            reject(err);
            log.error(err, { slug: key });
         } else {
            resolve({
               buffer,
               eTag: key + '_' + new Date().getTime().toString(),
               type
            });
         }
      });
   });
开发者ID:Trail-Image,项目名称:blog,代码行数:28,代码来源:view.ts

示例8:

 ].forEach(async p => {
    if (is.value(p) && !p.isAuthenticated) {
       const url = await p.authorizationURL();
       res.redirect(url);
       return;
    }
 });
开发者ID:Trail-Image,项目名称:blog,代码行数:7,代码来源:auth.ts

示例9: caption

/**
 * Convert new lines to HTML paragraphs and normalize links.
 *
 * @see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace
 */
function caption(text: string): string {
   if (!is.empty(text)) {
      const ph = '[POEM]'; // poetry placeholder
      let footnotes = '';
      let poem = '';

      text = fixMalformedLink(text);
      text = shortenLinkText(text);
      text = typography(text);

      text = text
         // format footnotes separately
         .replace(
            re.footnote.text,
            (_match: string, _prefix: string, body: string) => {
               footnotes = formatNotes(body);
               return '';
            }
         )
         // set poetry aside and replace with placeholder
         .replace(
            re.poetry.any,
            (_match: string, _space: string, body: string) => {
               poem = formatPoem(body);
               return ph;
            }
         )
         // remove block quotes and wrap in fake tags that won't match subsequent operations
         .replace(
            re.quote.block,
            (_match: string, _newLines: string, body: string) =>
               '[Q]' + body.replace(re.quote.curly, '') + '[/Q]'
         );

      text = '<p>' + text + '</p>';

      text = text
         .replace(re.newLine, '</p><p>')
         .replace(re.tag.emptyParagraph, '')
         .replace(
            re.quip,
            (_match, _tag: string, body: string) => '<p class="quip">' + body
         )
         .replace(re.footnote.number, '$1<sup>$2</sup>')
         // restore blockquotes
         .replace(/\[\/Q][\r\n\s]*([^<]+)/g, '[/Q]<p class="first">$1')
         .replace(/(<p>)?\[Q]/g, '<blockquote><p>')
         .replace(/\[\/Q](<\/p>)?/g, '</p></blockquote>');

      if (poem.length > 0) {
         text = text
            .replace(ph, '</p>' + poem + '<p class="first">')
            .replace(re.tag.emptyParagraph, '');
      }
      return text + footnotes;
   }
   return '';
}
开发者ID:Trail-Image,项目名称:blog,代码行数:63,代码来源:html.ts

示例10: seasonal

/**
 * Update seasonal restriction field.
 */
function seasonal(
   vehicleKey: string,
   from: MapProperties,
   out: MapProperties
): void {
   if (is.defined(from, vehicleKey)) {
      out[vehicle[vehicleKey] + ' Allowed'] = from[vehicleKey];
   }
}
开发者ID:Trail-Image,项目名称:blog,代码行数:12,代码来源:mapsource.ts


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