Comparing version 1.1.2 to 1.1.3
@@ -10,13 +10,13 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const cronLogic_1 = require("./cronLogic"); | ||
const random_1 = require("./random"); | ||
let uuidv4Value = new Error(constants_1.UUID_INIT_ERROR); | ||
let randomUsers = []; | ||
let numOfRandomsInTimeP = constants_1.NUM_OF_UUID_INIT; | ||
let globalNumberOfUUIDS = constants_1.NUM_OF_UUID_INIT; | ||
let job; | ||
let initialized = false; | ||
let initializedLimited = false; | ||
function init(humanCron, numOfRandomsInTime) { | ||
function init(humanCron, numOfRandomsInTime = globalNumberOfUUIDS) { | ||
const cronTime = (0, human_to_cron_1.default)(humanCron); | ||
uuidv4Value = (0, uuid_1.v4)(); | ||
if (!numOfRandomsInTime || typeof numOfRandomsInTime !== 'number') { | ||
if (!numOfRandomsInTime) { | ||
initialized = true; | ||
@@ -29,6 +29,6 @@ job = new cron_1.CronJob(cronTime, () => { | ||
initializedLimited = true; | ||
numOfRandomsInTimeP = numOfRandomsInTime; | ||
randomUsers = (0, cronLogic_1.computeJobWithLimitedRandoms)(cronTime, numOfRandomsInTime); | ||
globalNumberOfUUIDS = numOfRandomsInTime; | ||
randomUsers = (0, random_1.getRandomUUIDS)(numOfRandomsInTime); | ||
job = new cron_1.CronJob(cronTime, () => { | ||
randomUsers = (0, cronLogic_1.computeJobWithLimitedRandoms)(cronTime, numOfRandomsInTime); | ||
randomUsers = (0, random_1.getRandomUUIDS)(numOfRandomsInTime); | ||
}, null, true, 'America/Los_Angeles'); | ||
@@ -50,3 +50,3 @@ } | ||
} | ||
return randomUsers[Math.floor(Math.random() * numOfRandomsInTimeP)]; | ||
return randomUsers[Math.floor(Math.random() * globalNumberOfUUIDS)]; | ||
} | ||
@@ -53,0 +53,0 @@ exports.uuidv4CronLimited = uuidv4CronLimited; |
{ | ||
"name": "uuid-cron", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "uuid-cron", | ||
@@ -12,3 +12,2 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"prepublish" : "npm run build", | ||
"start": "npm run build && npm run serve", | ||
@@ -24,3 +23,6 @@ "serve": "node dist/index.js", | ||
}, | ||
"keywords": [ "cron", "uuid"], | ||
"keywords": [ | ||
"cron", | ||
"uuid" | ||
], | ||
"author": "", | ||
@@ -37,2 +39,3 @@ "license": "MIT", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"eslint": "^8.0.1", | ||
@@ -39,0 +42,0 @@ "eslint-config-airbnb-base": "^14.2.1", |
@@ -11,4 +11,4 @@ # uuid-cron | ||
**2. Init cron job** | ||
```javascript | ||
const { init, uuidv4CronLimited, stop } = require('uuid-cron'); | ||
```typescript | ||
import { init, uuidv4CronLimited, stop } from 'uuid-cron'; | ||
// for the first param, read cron syntax here: https://www.npmjs.com/package/human-to-cron | ||
@@ -19,3 +19,3 @@ init('each 20 seconds'); | ||
**3. uuidv4Cron() will return random uuid every 20 seconds** | ||
```javascript | ||
```typescript | ||
const randomUUID = uuidv4Cron(); | ||
@@ -25,3 +25,3 @@ ``` | ||
**4. On finish, stop the cron job, otherwise it will continue infinitely** | ||
```javascript | ||
```typescript | ||
stop(); | ||
@@ -32,3 +32,3 @@ ``` | ||
use uuidv4CronLimited to control the number of uuids generated in each cron job | ||
```javascript | ||
```typescript | ||
init('each 20 seconds', 30); | ||
@@ -35,0 +35,0 @@ // each 20 second generate 30 random uuids and return one of them each time |
import { init, uuidv4CronLimited, uuidv4Cron, stop } from '../src'; | ||
let uuidOriginal; | ||
let uuidTarget; | ||
describe('General functionality', () => { | ||
@@ -5,0 +6,0 @@ afterEach(() => { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21
15690
10
135