Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
gengenerator
Advanced tools
gengenerator is a useless generator. Don't be serious. Here is also a repository to collect examples for ES6 generator.
To install the stable version
$ npm install gengenerator
Define a global gengenerator
const gengenerator = require('gengenerator');
gengenerator(any, generator)
any
can be any primitive data types
generator
is a generator function with one parameter
const counter = gengenerator({ count: 0 }, function * f(init) {
while(1) {
yield init.count++;
}
});
console.log(counter.next().value); // 0
console.log(counter.next().value); // 1
console.log(counter.next().value); // 2
const ticker = gengenerator({
index: 1,
day: new Date().toISOString().substring(0, 10)
}, function * f(init) {
while(1) {
let today = new Date().toISOString().substring(0, 10);
if(init.day !== today) {
init.day = today;
init.index = 1;
}
yield `${init.day}-${init.index++}`;
}
});
console.log(ticker.next().value); // 2016-01-01-1
console.log(ticker.next().value); // 2016-01-01-2
console.log(ticker.next().value); // 2016-01-01-3
// Run in next day, maybe change your system time right now and test it
console.log(ticker.next().value); // 2016-01-02-1
Intercept a value with .next
. Guess a number between 1 and 100.
const bingo = gengenerator({
min: 0,
max: 101,
bonus: 30, // You can make it random
}, function * f(init) {
const io = (min, max) => `${min} - ? - ${max}`;
while(1) {
let input = yield io(init.min, init.max);
if(input <= init.min || input >= init.max) {
console.log('Wrong input, input again');
}
if(input === init.bonus) {
return 'Bingo!';
}
if(input < init.bonus && input > init.min) {
init.min = input;
} else if(input > init.bonus && input < init.max) {
init.max = input;
}
}
});
bingo.next(); // Start the game
console.log(bingo.next(31).value); // 0 - ? - 31
console.log(bingo.next(29).value); // 29 - ? - 31
console.log(bingo.next(30).value); // Bingo!
Have fun !
We're happy to discuss and see suggestions. Feel free to contribute in order to see the power of generator.
Copyright (C) 2016 Tony Ngan, released under the MIT License.
FAQs
A useless generator
The npm package gengenerator receives a total of 0 weekly downloads. As such, gengenerator popularity was classified as not popular.
We found that gengenerator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.