本文整理汇总了TypeScript中@jonggrang/prelude.just函数的典型用法代码示例。如果您正苦于以下问题:TypeScript just函数的具体用法?TypeScript just怎么用?TypeScript just使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了just函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getContentStream
function getContentStream(stream: Readable, headers: RequestHeaders): Maybe<Readable> {
const ce = String(headers['content-encoding'] || 'identity').toLowerCase();
return ce === 'identity' ? just(stream)
: ce === 'gzip' ? just(stream.pipe(createGunzip()))
: ce === 'deflate' ? just(stream.pipe(createInflate()))
: nothing;
}
示例2: toPiece
export function toPiece(t: string): Maybe<Piece> {
if (t.length === 0) return just(t);
if (t.charAt(0) === '.') return nothing;
for (let i = 0, len = t.length; i < len; i++) {
if (t.charAt(i) === '/') return nothing;
}
return just(t);
}
示例3: sendRsp
function sendRsp(
conn: Z.Connection,
ii: Z.InternalInfo,
status: H.Status,
headers: H.ResponseHeaders,
rsp: Rsp
): T.Task<[P.Maybe<H.Status>, P.Maybe<number>]> {
switch (rsp.tag) {
case RspType.RSPBUFFER:
return conn.writeHead(status, headers)
.chain(() => conn.sendAll(rsp.buffer))
.then(T.pure([P.just(status), P.just(Buffer.byteLength(rsp.buffer))] as [P.Maybe<H.Status>, P.Maybe<number>]));
case RspType.RSPREADABLE:
return conn.writeHead(status, headers)
.chain(_ => conn.sendStream(rsp.readable))
.map(_ => [P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]);
case RspType.RSPNOBODY:
return conn.writeHead(status, headers)
.then(T.pure([P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]));
case RspType.RSPFILE:
if (rsp.part != null) {
const part = rsp.part;
return sendRspFile2XX(conn, ii, status, addContentHeadersForFilePart(headers, part),
rsp.path, part.offset, part.byteCount, rsp.isHead);
}
return T.attempt(ii.getFinfo(rsp.path))
.chain(efinfo => {
if (P.isLeft(efinfo)) {
return sendRspFile404(conn, ii, headers);
}
const rspFile = conditionalRequest(efinfo.value, headers, rsp.header);
switch (rspFile.tag) {
case RspFileInfoType.WITHBODY:
return sendRspFile2XX(conn, ii, rspFile.status, rspFile.header, rsp.path,
rspFile.offset, rspFile.length, rsp.isHead);
case RspFileInfoType.WITHOUTBODY:
return sendRsp(conn, ii, rspFile.status, headers, { tag: RspType.RSPNOBODY });
}
});
case RspType.RSPSTREAM:
return conn.writeHead(status, headers)
.chain(_ => rsp.body(buff => conn.sendAll(buff)))
.map(_ => [P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]);
/* istanbul ignore next */
default:
throw new TypeError('last argument to sendRsp must be Rsp');
}
}
示例4: getRequestBodyType
export function getRequestBodyType(req: Request): Maybe<RequestBodyType> {
const parsed = safeParseContentType(req);
if (isNothing(parsed)) return nothing;
const { type, parameters } = parsed.value;
if (type && type.indexOf('multipart') === 0)
return just({ tag: 'multipart', boundary: parameters.boundary || '' } as RequestBodyType);
if (type === 'application/x-www-form-urlencoded')
return just({ tag: 'urlencoded', charset: parameters.charset } as RequestBodyType);
return nothing;
}
示例5: calculateCookieLife
export function calculateCookieLife(now: number, clife: CookieLife): E.Maybe<[number, Date]> {
switch (clife.tag) {
case CookieLifeType.SESSION:
return E.nothing;
case CookieLifeType.MAXAGE:
return E.just([clife.maxAge, new Date(now + (clife.maxAge * 1000))] as [number, Date]);
case CookieLifeType.EXPIRES:
return E.just([ (clife.expires.getTime() - now) / 1000, clife.expires ] as [number, Date]);
case CookieLifeType.EXPIRED:
return E.just([ 0, new Date(0) ] as [number, Date]);
}
}
示例6: just
.map(mstate => {
if (isLeft(mstate)) return nothing;
const stat = mstate.value;
// check if this is regular file
if (stat.isFile()) {
return just(mkFile(
stat.size,
(s, h) => W.responseFile(s, h, fp),
name,
hashFn(stat, weakEtags),
just(stat.mtime)
));
}
return nothing;
});
示例7: while
export function lookup<A>(k: number, im: IntMap<A>): P.Maybe<A> {
while (true) {
if (im.tag === IntMapType.NIL) {
return P.nothing;
}
if (im.tag === IntMapType.TIP) {
if (k === im.key) {
return P.just(im.value);
}
return P.nothing;
}
if (im.tag === IntMapType.BIN) {
if (!I.matchPrefix(im.prefix, im.mask, k)) {
return P.nothing;
}
if (I.branchLeft(im.mask, k)) {
im = im.left;
continue;
}
im = im.right;
continue;
}
throw new TypeError('invalid invariant IntMap detected in lookup function');
}
}
示例8: it
it('return the cookie in array', () => {
const ret = CO.lookupCookieValue('foo', [
CO.createCookieKV('foo', 'bar'),
CO.createCookieKV('baz', 'bazz')
]);
assert.deepEqual(ret, P.just('bar'));
});
示例9: parseHTTPDate
export function parseHTTPDate(str: string): P.Maybe<HttpDate> {
const ret = PS.runParser(rfc1123Date, str);
if (P.isRight(ret)) {
return P.just(ret.value);
}
return P.nothing;
}
示例10: safeParseContentType
/**
* wrap parse content type, as it may throw exception
*/
function safeParseContentType(req: Request) {
try {
return just(parseContentType(req));
} catch {
return nothing;
}
}