@syncot/util
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -7,3 +7,4 @@ export * from './buffer'; | ||
export * from './stream'; | ||
export * from './taskRunner'; | ||
export * from './types'; | ||
export * from './validation'; |
@@ -7,2 +7,3 @@ export * from './buffer'; | ||
export * from './stream'; | ||
export * from './taskRunner'; | ||
export * from './validation'; |
@@ -5,6 +5,11 @@ export declare function noop(): void; | ||
*/ | ||
export declare function whenNextTick(): Promise<{}>; | ||
export declare function whenNextTick(): Promise<unknown>; | ||
/** | ||
* Returns a Promise that resolves after the specified minimum number of milliseconds. | ||
*/ | ||
export declare function delay(minDelayMilliseconds?: number): Promise<{}>; | ||
export declare function delay(minDelayMilliseconds?: number): Promise<unknown>; | ||
/** | ||
* Generates a unique ID using an approach inspired by MongoDB ObjectID. | ||
* See https://docs.mongodb.com/manual/reference/method/ObjectId/. | ||
*/ | ||
export declare function generateId(): string; |
@@ -0,1 +1,2 @@ | ||
import { randomFillSync } from 'crypto'; | ||
export function noop() { | ||
@@ -16,1 +17,16 @@ // Do nothing. | ||
} | ||
const randomIdBuffer = Buffer.allocUnsafeSlow(12); | ||
randomFillSync(randomIdBuffer, 4); | ||
let randomIdCounter = randomIdBuffer.readUIntBE(9, 3); | ||
/** | ||
* Generates a unique ID using an approach inspired by MongoDB ObjectID. | ||
* See https://docs.mongodb.com/manual/reference/method/ObjectId/. | ||
*/ | ||
export function generateId() { | ||
/* tslint:disable-next-line:no-bitwise */ | ||
randomIdBuffer.writeIntBE((Date.now() * 0.001) | 0, 0, 4); | ||
randomIdBuffer.writeUIntBE(randomIdCounter, 9, 3); | ||
/* tslint:disable-next-line:no-bitwise */ | ||
randomIdCounter = (randomIdCounter + 1) & 0x00ffffff; | ||
return randomIdBuffer.toString('base64'); | ||
} |
{ | ||
"name": "@syncot/util", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A collection of utilities required by other @syncot modules.", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@types/node": "^10.12.21", | ||
"@types/node": "^12.0.4", | ||
"@types/readable-stream": "^2.3.1", | ||
@@ -35,3 +35,3 @@ "readable-stream": "^3.3.0", | ||
}, | ||
"gitHead": "f42e7403c10d1236587af99fc13d35b2a27a55ad" | ||
"gitHead": "888dd1570ed3023173b3b5bbafad0f29271b246f" | ||
} |
24979
22
635
+ Added@types/node@12.20.55(transitive)
- Removed@types/node@10.17.60(transitive)
Updated@types/node@^12.0.4