yuenc
v1.0.0
Published
yuenc modules, Some methods commonly used by browsers
Downloads
1
Maintainers
Readme
yuenc
FastBuffer
import { FastBuffer } from 'yuenc/buffer'
// or
const { FastBuffer } = require('yuenc').buffer
declare type Encoding = "ascii" | "base64" | "binary" | "hex" | "latin1" | "utf8";
export declare class FastBuffer extends Uint8Array {
static alloc(size: number, fill?: string, encoding?: Encoding): FastBuffer;
static from(str: string, encoding?: Encoding): FastBuffer;
toString(encoding?: Encoding, start?: number, end?: number): string;
...
}
FastBuffer.alloc(2)
// FastBuffer(2) [0, 0]
FastBuffer.alloc(2, 1)
// FastBuffer(2) [1, 1]
FastBuffer.alloc(2, "abc")
// FastBuffer(2) [97, 98]
FastBuffer.alloc(2, "abc", "base64")
// FastBuffer(2) [105, 183]
const fastBuf = FastBuffer.from("测试")
// FastBuffer(6) [230, 181, 139, 232, 175, 149]
fastBuf.toString()
// 测试
crypto
import { createHash } from 'yuenc/crypto'
// or
const { createHash } = require('yuenc').crypto
declare type KAlgorithm = "sha1" | "sha256" | "sha384" | "sha512"
declare function createHash(algorithm: KAlgorithm): Hash;
await createHash("sha256").update("123456").digest("hex")
// '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
querystring
import { querystring } from 'yuenc/querystring'
// or
const { querystring } = require('yuenc').querystring
querystring.encode({
foo: 'bar',
abc: ['xyz', '123']
})
// foo=bar&abc=xyz&abc=123
querystring.decode('foo=bar&abc=xyz&abc=123')
// {
// foo: 'bar',
// abc: ['xyz', '123']
// }