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


TypeScript is.defined方法代碼示例

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


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

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

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

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


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