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


TypeScript cryptic.randomString函数代码示例

本文整理汇总了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));
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:15,代码来源:storage-test.ts

示例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
       })
     );
   });
 }
开发者ID:syaiful6,项目名称:jonggrang,代码行数:14,代码来源:disk.ts

示例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
开发者ID:syaiful6,项目名称:jonggrang,代码行数:31,代码来源:session.ts

示例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* () {
开发者ID:syaiful6,项目名称:jonggrang,代码行数:31,代码来源:storage-test.ts


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