本文整理汇总了TypeScript中@jonggrang/object.assign函数的典型用法代码示例。如果您正苦于以下问题:TypeScript assign函数的具体用法?TypeScript assign怎么用?TypeScript assign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assign函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('saveSession can replace old session with new one', async function () {
const storage = await T.toPromise(emptyMockStorage);
const state = SS.createServerSessionState(storage);
const m1 = { a: 'b' };
const sess1 = await T.toPromise(SS.saveSession(state, { sess: null, now: fakenow }, m1));
const m2 = SO.insert(state.authKey, 'John', m1);
const sess2 = await T.toPromise(SS.saveSession(state, { sess: sess1, now: fakenow }, m2));
const m3 = SO.insert(SS.forceInvalidateKey, SS.ForceInvalidate.ALL_SESSION_IDS_OF_LOGGED_USER, m2 as any);
const sess3 = await T.toPromise(SS.saveSession(state, { sess: sess2, now: fakenow }, m3));
await getMockOperation(storage);
const m4 = SO.insert('x', 'y', m2);
const sess4 = await T.toPromise(SS.saveSession(state, { sess: sess3, now: fakenow }, m4));
assert.deepEqual(sess4, SO.assign({}, sess3, { data: SO.remove(state.authKey, m4) }));
const op = await getMockOperation(storage);
assert.deepEqual(op, L.fromArray([
{ tag: 'replace', session: sess4 }
]));
});
示例2: pipeStream
return pipeStream(outStream, source as any).map(() =>
assign(file, {
filename,
size: outStream.bytesWritten,
path: finalPath,
move: handleMove
})
示例3: addContentHeaders
function addContentHeaders(hs: H.ResponseHeaders, off: number, len: number, size: number): H.ResponseHeaders {
const hs2 = SM.assign({}, hs, {
'Content-Length': len,
'Accept-Ranges': 'bytes'
});
if (len === size) return hs2;
hs2['Content-Ranges'] = contentRangeHeader(off, off + len - 1, size);
return hs2;
}
示例4: 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);
}
});
示例5: rspFileInfo
.chain(efinfo => {
if (isLeft(efinfo)) {
assert.equal(true, false);
return T.pure(false);
}
const { value: finfo } = efinfo;
let hs = S.assign({}, rsp.header, {
'Last-Modified': finfo.date
});
let rsp2 = rspFileInfo(RspFileInfoType.WITHBODY, rsp.status, hs, rsp.offset, rsp.length);
assert.deepEqual(conditionalRequest(finfo, {}, headers), rsp2);
return T.pure(false);
});
示例6: cacheControl
export function cacheControl(maxage: MaxAge, headers: H.ResponseHeaders): H.ResponseHeaders {
let cInt: number | null = null;
if (maxage.tag === MaxAgeType.MaxAgeSeconds) {
cInt = maxage.seconds;
}
if (maxage.tag === MaxAgeType.MaxAgeForever) {
cInt = 31536000;
}
let extraHeaders: H.ResponseHeaders = S.assign({}, headers);
if (cInt != null) {
extraHeaders['Cache-Control'] = `public, max-age=${cInt}`;
}
if (maxage.tag === MaxAgeType.MaxAgeForever) {
extraHeaders['Expires'] = 'Thu, 31 Dec 2037 23:55:55 GMT';
}
return extraHeaders;
}
示例7: removePlaceholder
T.runTask(storage.handleFile(file, filestream as any), (err, finfo) => {
// sometimes the limit event was fired before we attach the listener
// so, check the truncated property here
if ((filestream as any).truncated && !aborting) filestream.emit('limit');
if (aborting) {
removePlaceholder(files, placeholder);
uploadedFiles.push(assign(file, finfo || {}) as any);
return pendingWrites.decrement();
}
if (err) {
removePlaceholder(files, placeholder);
pendingWrites.decrement();
return abortWithError(err);
}
replacePlaceholder(files, placeholder, finfo as any);
uploadedFiles.push(finfo as any);
pendingWrites.decrement();
indicateDone();
});
示例8: getBuffer
return getBuffer(source).map(buffer =>
assign(file, {
buffer,
size: buffer.length,
move: writeFile
})
示例9: sendResponse
.chain(mime => {
const headers = S.assign({}, srespond.headers, {
'Content-Type': mime
});
return sendResponse(file.toResponse(200, headers));
});