koishi-utils
Advanced tools
Comparing version 3.0.0 to 3.0.1
declare type CQCodeData = Record<string, string | number | boolean>; | ||
interface CQCode { | ||
export interface CQCode { | ||
type: string; | ||
@@ -11,3 +11,3 @@ data: CQCodeData; | ||
} | ||
declare namespace CQCode { | ||
export declare namespace CQCode { | ||
function escape(source: any, insideCQ?: boolean): string; | ||
@@ -20,2 +20,2 @@ function unescape(source: string): string; | ||
} | ||
export default CQCode; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CQCode = void 0; | ||
var CQCode; | ||
@@ -68,4 +69,3 @@ (function (CQCode) { | ||
CQCode.parseAll = parseAll; | ||
})(CQCode || (CQCode = {})); | ||
exports.default = CQCode; | ||
})(CQCode = exports.CQCode || (exports.CQCode = {})); | ||
//# sourceMappingURL=cqCode.js.map |
@@ -1,3 +0,3 @@ | ||
import CQCode from './cqCode'; | ||
export * from './chinese'; | ||
export * from './cqCode'; | ||
export * from './logger'; | ||
@@ -10,2 +10,1 @@ export * from './misc'; | ||
export * from './time'; | ||
export { CQCode }; |
@@ -12,10 +12,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CQCode = void 0; | ||
const cqCode_1 = __importDefault(require("./cqCode")); | ||
exports.CQCode = cqCode_1.default; | ||
__exportStar(require("./chinese"), exports); | ||
__exportStar(require("./cqCode"), exports); | ||
__exportStar(require("./logger"), exports); | ||
@@ -22,0 +17,0 @@ __exportStar(require("./misc"), exports); |
@@ -1,2 +0,1 @@ | ||
export declare function randomId(length?: number): string; | ||
/** | ||
@@ -27,24 +26,27 @@ * random operations | ||
splice<T>(source: T[]): T; | ||
weightedPick<T extends string>(weights: Record<T, number>): T; | ||
weightedPick<T extends string>(weights: Readonly<Record<T, number>>): T; | ||
} | ||
/** | ||
* random real | ||
* @param start start number | ||
* @param end end number | ||
* @returns a random real in the interval [start, end) | ||
*/ | ||
export declare function randomReal(end: number): number; | ||
export declare function randomReal(start: number, end: number): number; | ||
/** | ||
* random integer | ||
* @param start start number | ||
* @param end end number | ||
* @returns a random integer in the interval [start, end) | ||
*/ | ||
export declare function randomInt(end: number): number; | ||
export declare function randomInt(start: number, end: number): number; | ||
export declare function randomPick<T>(source: readonly T[]): T; | ||
export declare function randomSplice<T>(source: T[]): T; | ||
export declare function randomMultiPick<T>(source: T[], count: number): T[]; | ||
export declare function randomWeightedPick<T extends string>(weights: Record<T, number>): T; | ||
export declare function randomBool(probability: number): boolean; | ||
export declare namespace Random { | ||
function uuid(): string; | ||
/** | ||
* random real | ||
* @param start start number | ||
* @param end end number | ||
* @returns a random real in the interval [start, end) | ||
*/ | ||
function real(end: number): number; | ||
function real(start: number, end: number): number; | ||
/** | ||
* random integer | ||
* @param start start number | ||
* @param end end number | ||
* @returns a random integer in the interval [start, end) | ||
*/ | ||
function int(end: number): number; | ||
function int(start: number, end: number): number; | ||
function pick<T>(source: readonly T[]): T; | ||
function shuffle<T>(source: readonly T[]): T[]; | ||
function multiPick<T>(source: T[], count: number): T[]; | ||
function weightedPick<T extends string>(weights: Readonly<Record<T, number>>): T; | ||
function bool(probability: number): boolean; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomBool = exports.randomWeightedPick = exports.randomMultiPick = exports.randomSplice = exports.randomPick = exports.randomInt = exports.randomReal = exports.Random = exports.randomId = void 0; | ||
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
function randomId(length = 8) { | ||
let output = ''; | ||
for (let index = length; index > 0; --index) { | ||
output += chars[Math.floor(Math.random() * 62)]; | ||
} | ||
return output; | ||
} | ||
exports.randomId = randomId; | ||
exports.Random = void 0; | ||
const crypto_1 = require("crypto"); | ||
/** | ||
@@ -53,38 +45,59 @@ * random operations | ||
exports.Random = Random; | ||
function randomReal(...args) { | ||
return new Random().real(...args); | ||
const hex = []; | ||
for (let i = 0; i < 256; ++i) { | ||
hex.push((i + 0x100).toString(16).substr(1)); | ||
} | ||
exports.randomReal = randomReal; | ||
function randomInt(...args) { | ||
return new Random().int(...args); | ||
} | ||
exports.randomInt = randomInt; | ||
function randomPick(source) { | ||
return new Random().pick(source); | ||
} | ||
exports.randomPick = randomPick; | ||
function randomSplice(source) { | ||
return new Random().splice(source); | ||
} | ||
exports.randomSplice = randomSplice; | ||
function randomMultiPick(source, count) { | ||
source = source.slice(); | ||
const result = []; | ||
const length = Math.min(source.length, count); | ||
for (let i = 0; i < length; i += 1) { | ||
const index = Math.floor(Math.random() * source.length); | ||
const [item] = source.splice(index, 1); | ||
result.push(item); | ||
(function (Random) { | ||
function uuid() { | ||
const arr = crypto_1.randomFillSync(new Uint8Array(16)); | ||
arr[6] = arr[6] & 0x0f | 0x40; | ||
arr[8] = arr[8] & 0x3f | 0x80; | ||
return hex[arr[0]] + hex[arr[1]] + hex[arr[2]] + hex[arr[3]] | ||
+ '-' + hex[arr[4]] + hex[arr[5]] + '-' + hex[arr[6]] + hex[arr[7]] | ||
+ '-' + hex[arr[8]] + hex[arr[9]] + '-' + hex[arr[10]] + hex[arr[11]] | ||
+ hex[arr[12]] + hex[arr[13]] + hex[arr[14]] + hex[arr[15]]; | ||
} | ||
return result; | ||
} | ||
exports.randomMultiPick = randomMultiPick; | ||
function randomWeightedPick(weights) { | ||
return new Random().weightedPick(weights); | ||
} | ||
exports.randomWeightedPick = randomWeightedPick; | ||
function randomBool(probability) { | ||
return new Random().bool(probability); | ||
} | ||
exports.randomBool = randomBool; | ||
Random.uuid = uuid; | ||
function real(...args) { | ||
return new Random().real(...args); | ||
} | ||
Random.real = real; | ||
function int(...args) { | ||
return new Random().int(...args); | ||
} | ||
Random.int = int; | ||
function pick(source) { | ||
return new Random().pick(source); | ||
} | ||
Random.pick = pick; | ||
function shuffle(source) { | ||
const clone = source.slice(); | ||
const result = []; | ||
for (let i = source.length; i > 0; --i) { | ||
result.push(new Random().splice(clone)); | ||
} | ||
return result; | ||
} | ||
Random.shuffle = shuffle; | ||
function multiPick(source, count) { | ||
source = source.slice(); | ||
const result = []; | ||
const length = Math.min(source.length, count); | ||
for (let i = 0; i < length; i += 1) { | ||
const index = Math.floor(Math.random() * source.length); | ||
const [item] = source.splice(index, 1); | ||
result.push(item); | ||
} | ||
return result; | ||
} | ||
Random.multiPick = multiPick; | ||
function weightedPick(weights) { | ||
return new Random().weightedPick(weights); | ||
} | ||
Random.weightedPick = weightedPick; | ||
function bool(probability) { | ||
return new Random().bool(probability); | ||
} | ||
Random.bool = bool; | ||
})(Random = exports.Random || (exports.Random = {})); | ||
//# sourceMappingURL=random.js.map |
@@ -5,2 +5,2 @@ export declare function contain(array1: readonly any[], array2: readonly any[]): boolean; | ||
export declare function union<T>(array1: readonly T[], array2: readonly T[]): T[]; | ||
export declare function deduplicate<T>(array: T[]): T[]; | ||
export declare function deduplicate<T>(array: readonly T[]): T[]; |
{ | ||
"name": "koishi-utils", | ||
"description": "Utilities for Koishi", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "typings": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75151
849