當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript is.empty方法代碼示例

本文整理匯總了TypeScript中@toba/tools.is.empty方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript is.empty方法的具體用法?TypeScript is.empty怎麽用?TypeScript is.empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@toba/tools.is的用法示例。


在下文中一共展示了is.empty方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: trails

function trails(from: MapProperties): MapProperties {
   const out: MapProperties = {};
   const miles: number = from['MILES'] as number;
   const who = 'Jurisdiction';
   let name: string = from['NAME'] as string;
   let label: string = from['name'] as string;

   if (miles && miles > 0) {
      out['Miles'] = miles;
   }
   if (is.value<string>(label)) {
      label = label.trim();
   }

   if (!is.empty(name) && !is.empty(label)) {
      name = titleCase(name.trim());
      // label is usually just a number so prefer name when supplied
      const num = label.replace(/\D/g, '');
      // some names alread include the road or trail number and
      // some have long numbers that aren't helpful
      label =
         (num.length > 1 && name.includes(num)) || num.length > 3
            ? name
            : name + ' ' + label;
   }

   if (label) {
      out['Label'] = label;
   }

   Object.keys(vehicle).forEach(key => {
      seasonal(key, from, out);
   });

   relabel(from, out, { JURISDICTION: who });

   if (is.defined(out, who)) {
      out[who] = titleCase(out[who] as string);
   }

   return out;
}
開發者ID:Trail-Image,項目名稱:blog,代碼行數:42,代碼來源:mapsource.ts

示例6: clientIP

export function clientIP(req: Request): string {
   let ipAddress = req.connection.remoteAddress;
   const forwardedIP = req.headers[Header.ForwardedFor] as string;

   if (!is.empty(forwardedIP)) {
      // contains delimited list like "client IP, proxy 1 IP, proxy 2 IP"
      const parts = forwardedIP.split(',');
      ipAddress = parts[0];
   }
   return IPv6(ipAddress);
}
開發者ID:Trail-Image,項目名稱:blog,代碼行數:11,代碼來源:view.ts

示例7:

export const typography = (text: string) =>
   is.empty(text)
      ? ''
      : text
           .replace(re.quote.rightSingle, '$1&rsquo;')
           .replace(re.quote.leftSingle, '&lsquo;$1')
           .replace(re.quote.rightDouble, '$1&rdquo;')
           .replace(re.quote.leftDouble, '&ldquo;$2')
           // restore straight quotes around link attributes
           .replace(
              re.tag.encodedLink,
              (_match, tag, name) =>
                 tag.replace(re.quote.html, '"') + name + '</a>'
           );
開發者ID:Trail-Image,項目名稱:blog,代碼行數:14,代碼來源:html.ts

示例8: return

   return (
      view: string,
      context: ViewContext,
      type?: MimeType,
      minify = false
   ) => {
      // use default meta tag description if none provided
      if (is.empty(context.description)) {
         context.description = config.site.description;
      }

      if (is.defined(context, 'jsonLD')) {
         context.linkData = serialize(context.jsonLD);
         delete context['jsonLD'];
      }

      // always send full config to views
      context.config = config;

      res.render(view, context, (renderError: Error, text: string) => {
         if (is.value(renderError)) {
            // error message includes view name
            log.error(`Rendering ${slug} ${renderError.message}`, { slug });
            internalError(res);
         } else {
            if (is.value<string>(text)) {
               if (minify) {
                  text = compact(text);
               }
               cacheAndSend(res, text, slug, type);
            } else {
               log.error(`renderTemplate(${slug}) returned no content`, {
                  slug
               });
               internalError(res);
            }
         }
      });
   };
開發者ID:Trail-Image,項目名稱:blog,代碼行數:39,代碼來源:view.ts

示例9:

export const IPv6 = (ip: string): string =>
   is.empty(ip) || ip === '::1'
      ? '127.0.0.1'
      : ip.replace(/^::[0123456789abcdef]{4}:/g, '');
開發者ID:Trail-Image,項目名稱:blog,代碼行數:4,代碼來源:view.ts


注:本文中的@toba/tools.is.empty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。