open-nomad/ui/mirage/utils.js
Buck Doyle 5da134d074
UI: Change Mirage data to be stable in development (#6389)
This sets a default-but-query-configurable Faker seed in development,
via faker-seed. It also changes uses of Math.random to use Faker’s
randomness so auto-generated data remains stable in development.
2019-10-03 09:13:08 -05:00

29 lines
574 B
JavaScript

import faker from 'nomad-ui/mirage/faker';
export function provide(count, provider) {
if (typeof count === 'function') {
count = count();
}
return Array(count)
.fill(null)
.map(provider);
}
export function provider() {
return () => provide(...arguments);
}
export function pickOne(list) {
return list[faker.random.number(list.length - 1)];
}
export function arrToObj(prop, alias = '') {
return (obj, element) => {
const name = element[prop];
delete element[prop];
obj[name] = alias ? element[alias] : element;
return obj;
};
}