當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。