Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import uniqueRandomArray from 'unique-random-array';
import starWarsNames from './starwars-names.json';
const getRandomItem = uniqueRandomArray(starWarsNames);
module.exports = {
all: starWarsNames,
random: random
};
function random(number) {
if (number === undefined) {
return getRandomItem();
} else {
const randomItems = [];
for (let i = 0; i < number; i++) {
randomItems.push(getRandomItem());
}
return randomItems;
}
import uniqueRandomArray from "unique-random-array";
import entries from "../data/entries";
export const all = entries;
export const random = uniqueRandomArray(entries);
export const getEntry = (id = 1) => {
const entry = entries[id - 1];
if (!entry) {
throw new Error("Invalid ID");
}
return entry;
};