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


TypeScript prelude.isJust函数代码示例

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


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

示例1: conditionModifiedRange

function conditionModifiedRange(finfo: FileInfo, hm: H.RequestHeaders): P.Maybe<RspFileInfo> {
  const im = ifModified(hm, finfo.size, finfo.time);
  if (P.isJust(im)) return im;
  const ium = ifUnmodifiedSince(hm, finfo.size, finfo.time);
  if (P.isJust(ium)) return ium;
  return ifRange(hm, finfo.size, finfo.time);
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:7,代码来源:file.ts

示例2: uriAuthEquals

function uriAuthEquals(s: P.Maybe<URIAuth>, d: P.Maybe<URIAuth>): boolean {
  if (P.isNothing(s) && P.isNothing(d)) return true;
  if (P.isJust(s) && P.isJust(d)) {
    const sa = s.value;
    const da = d.value;
    const uriAuth: (keyof URIAuth)[] = ['userInfo', 'port', 'regName'];
    return uriAuth.every(x => sa[x] === da[x]);
  }
  return false;
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:index.ts

示例3: switch

    .chain(srespond => {
      switch (srespond.tag) {
        case StaticResponseType.FILERESPONSE:
          const { file } = srespond;
          return ss.getMimeType(file)
            .chain(mime => {
              const headers = S.assign({}, srespond.headers, {
                'Content-Type': mime
              });
              return sendResponse(file.toResponse(200, headers));
            });

        case StaticResponseType.NOTMODIFIED:
          return sendResponse(W.responseBuffer(304, {}, Buffer.from('')));

        case StaticResponseType.SENDCONTENT:
          return sendResponse(W.responseReadable(200, {
            'Content-Type': srespond.mimeType
          }, srespond.readable));

        case StaticResponseType.REDIRECT:
          const reqQs = url.parse(req.url as string, true).query;
          const loc = ss.mkRedirect(srespond.pieces, srespond.pieces.map(encodeURIComponent).join('/'));
          const qString =
            P.isJust(srespond.hash)
            ? S.assign({}, reqQs, { etag: srespond.hash.value })
            : S.remove('etag', reqQs as any);
          const qs = H.renderQuery(qString as any);
          return sendResponse(W.responseBuffer(301, {
            'Content-Type': 'text/plain',
            Location: loc + (qs !== '' ? `?${qs}` : '')
          }, Buffer.from('')));

        case StaticResponseType.RAWREDIRECT:
          return sendResponse(W.responseBuffer(301, {
            'Content-Type': 'text/plain',
            Location: srespond.path
          }, Buffer.from('Redirect')));

        case StaticResponseType.NOTFOUND:
          if (P.isJust(ss.notFoundHandler)) {
            return ss.notFoundHandler.value(ctx, sendResponse);
          }
          return sendResponse(W.responseBuffer(404, {
            'Content-Type': 'text/plain'
          }, Buffer.from('File not found')));

        case StaticResponseType.WAIRESPONSE:
          return sendResponse(srespond.response);
      }
    });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:51,代码来源:static.ts

示例4: renderDirectoryContentsTable

function renderDirectoryContentsTable(pieces: Piece[], folder: Folder): string {
  let table = [
    '<table>',
    '  <thead>',
    '    <th class="first"></th>', // todo image
    '    <th>Name</th>',
    '    <th>Modified</th>',
    '    <th>Size</th>',
    '  </thead>',
    '  <tbody>'
  ].join('\n');

  const sorted = folder.sort(compareFolder);
  let alt: boolean;
  let item: Either<FolderName, File>;
  let name: string;
  let href: string;
  for (let i = 0, len = sorted.length; i < len; i++) {
    alt = (i % 2) === 0;
    item = sorted[i];
    name = isLeft(item) ? (item.value === '' ? '..' : item.value) : item.value.name;
    href = addCurrentDir(pieces, name)
    table += alt ? '<tr class="alt">' : '<tr>\n';
    table += `<td class="first${isLeft(item) ? ' icon-dir' : ''}"></td>\n`;
    table += `<td><a href="${href}">${name}</a></td>\n`;
    table += `<td>${isRight(item) && isJust(item.value.getModified)
      ? formatCalender(item.value.getModified.value) : ''}</td>\n`;
    table += `<td>${isRight(item) ? prettyShow(item.value.size) : ''}</td>\n`;
    table += '</tr>\n';
  }

  table += '  </tbody>\n';
  table += '</table>\n';
  return table;
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:35,代码来源:listing.ts

示例5: run

  run(t1: IntMap<A>): IntMap<A> {
    let ret: P.Maybe<A>;
    const { f, k } = this;
    switch (t1.tag) {
      case IntMapType.NIL:
        return empty;

      case IntMapType.TIP:
        if (k === t1.key) {
          ret = f(k, t1.value);
          if (P.isJust(ret)) {
            return TipIM(t1.key, ret.value);
          }
          return empty;
        }
        return t1;

      case IntMapType.BIN:
        if (!I.matchPrefix(t1.prefix, t1.mask, k)) {
          return t1;
        }
        if (I.branchLeft(t1.mask, k)) {
          return BinNE(t1.prefix, t1.mask, this.run(t1.left), t1.right);
        }
        return BinNE(t1.prefix, t1.mask, t1.left, this.run(t1.right));

      default:
        throw new TypeError('Invalid invariant intmap detected in updateWithKey');
    }
  }
开发者ID:syaiful6,项目名称:jonggrang,代码行数:30,代码来源:index.ts

示例6: combine

 function combine(t1x: IntMap<A>, t2x: IntMap<B>): IntMap<C> {
   if (t1x.tag === IntMapType.TIP && t2x.tag === IntMapType.TIP) {
     const ma = f(t1x.key, t1x.value, t2x.value);
     if (P.isJust(ma)) return TipIM(t1x.key, ma.value);
     return empty;
   }
   return empty;
 }
开发者ID:syaiful6,项目名称:jonggrang,代码行数:8,代码来源:index.ts

示例7: Error

 return fcache.read.chain(cache => {
   const there = HM.lookup(hash, path, cache);
   if (isJust(there)) {
     const entry = there.value;
     return entry.tag === EntryType.NEGATIVE ? T.raise(new Error('FileInfoCache:getAndRegisterInfo'))
       : T.pure(entry.finfo);
   }
   return T.rescue(positive(fcache, hash, path), () => negative(fcache, hash, path));
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:9,代码来源:file-info.ts

示例8: defaultOnExceptionEff

function defaultOnExceptionEff(mreq: P.Maybe<IncomingMessage>, err: Error) {
  if (P.isJust(mreq)) {
    const req = mreq.value;
    console.error(
      `error when handle request ${req.method} ${req.url} with error message ${err.message}`
    );
  } else {
    console.error(err.message);
  }
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:settings.ts

示例9: respond

      .chain(mHash => {
        const lastHash = req.headers['if-none-match'];
        if (lastHash != null && P.isJust(mHash)) {
          const curHash = mHash.value;
          if (ss.weakEtags && (lastHash === curHash || lastHash === `W/${curHash}`
              || `W/${lastHash}` === curHash)) {
            return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
          }

          if (!ss.weakEtags && (curHash === lastHash && lastHash.indexOf('W/') !== 0)) {
            return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
          }
        }

        if (P.isJust(mHash)) {
          return respond({ 'ETag': mHash.value });
        }
        return lastMod;
      });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:19,代码来源:static.ts

示例10: serveFile

export function serveFile(ss: StaticSettings, req: IncomingMessage, file: File): T.Task<StaticResponse> {
  const mLastSent = ifMofiedSince_(req.headers);
  const mdate = P.mapMaybe(file.getModified, H.fromDate);

  function respond(headers: H.ResponseHeaders): T.Task<StaticResponse> {
    return T.pure({
      file,
      headers: cacheControl(ss.maxAge, headers),
      tag: StaticResponseType.FILERESPONSE } as StaticResponse
    );
  }

  const lastMod = P.isJust(mdate) && P.isJust(mLastSent) && mdate.value.equals(mLastSent.value)
    ? T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse)
      : P.isJust(mdate) ? respond({ 'Last-Modified': H.formatHttpDate(mdate.value) })
        : respond({});

  if (ss.useHash) {
    return file.getHash
      .chain(mHash => {
        const lastHash = req.headers['if-none-match'];
        if (lastHash != null && P.isJust(mHash)) {
          const curHash = mHash.value;
          if (ss.weakEtags && (lastHash === curHash || lastHash === `W/${curHash}`
              || `W/${lastHash}` === curHash)) {
            return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
          }

          if (!ss.weakEtags && (curHash === lastHash && lastHash.indexOf('W/') !== 0)) {
            return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
          }
        }

        if (P.isJust(mHash)) {
          return respond({ 'ETag': mHash.value });
        }
        return lastMod;
      });
  }
  return lastMod;
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:41,代码来源:static.ts


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