本文整理汇总了TypeScript中@jonggrang/cryptic.randomString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript randomString函数的具体用法?TypeScript randomString怎么用?TypeScript randomString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randomString函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: yield
return T.co(function* () {
const id: string = yield generateSessionId;
const authId: null | string = yield (
auth === HasAuthId.HAS_AUTH_ID ? generateSessionId
: T.pure(null));
const keys: string[] = yield T.sequencePar(replicateArr(20, randomString(8)));
const values: string[] = yield T.sequencePar(replicateArr(20, randomString(16)));
const data = fromPairs(zip(keys, values));
const now = Date.now();
return T.pure(createSession(id, authId, data, now - 1000, now));
});
示例2: handleFile
handleFile(file: FileUpload, source: Readable): T.Task<FileInfo> {
return randomString(32).chain(filename => {
const finalPath = path.join(this.opts.dir, filename);
const outStream = fs.createWriteStream(finalPath);
return pipeStream(outStream, source as any).map(() =>
assign(file, {
filename,
size: outStream.bytesWritten,
path: finalPath,
move: handleMove
})
);
});
}
示例3: randomString
import { deepEq } from '@jonggrang/prelude';
import { drop, insert, isEmpty } from '@jonggrang/object';
import * as T from '@jonggrang/task';
import { randomString } from '@jonggrang/cryptic';
/**
* The Id of a session
*/
export type SessionId = string;
// Securely generate a new SessionId.
export const generateSessionId: T.Task<SessionId> = randomString(32);
// Value of the `authKey' in session
export type AuthId = string;
// Session data are simple JS object
export type SessionData = Record<string, any>;
/**
* Representation of a saved session.
*/
export interface Session {
/**
* session's id, primary key
*/
id: SessionId;
/**
* Value of `authId`, separate from rest
示例4: randomString
} from './session';
export const enum HasAuthId {
HAS_AUTH_ID,
NO_AUTH_ID
}
export interface ItFn {
(desc: string, fn: () => Promise<any>): void;
}
/**
* Generate random auth for our test
*/
const generateAuthId = randomString(16);
export function allStorageTest(storage: Storage, _it: ItFn) {
const run = storage.runTransaction;
function it(des: string, fn: () => Iterator<T.Task<any>>): void {
_it(des, () => T.toPromise(T.co(fn)));
}
it('runTransaction should be sane', function* () {
const ret: number = yield run(T.pure(42));
assert.equal(ret, 42);
return T.pure(true);
});
it('storage.get should return null for inexisten key', function* () {