UNPKG

807 BJavaScriptView Raw
1import { type } from '@antv/dw-analyzer';
2import { Random, TextRandom } from '@antv/dw-random';
3/**
4 *
5 * @param sample
6 * @todo optimize this temp funciton
7 */
8export function oneMoreValue(sample) {
9 var dataProps = type(sample);
10 var isUnique = dataProps.count === dataProps.distinct;
11 var tr = new TextRandom();
12 var r = new Random();
13 if (dataProps.recommendation === 'string') {
14 if (isUnique) {
15 // @ts-ignore
16 return tr.word({ length: r.n(r.natural, 1, { min: dataProps.minLength, max: dataProps.maxLength })[0] });
17 }
18 else {
19 return dataProps.samples[Math.floor(Math.random() * dataProps.samples.length)];
20 }
21 }
22 else {
23 return dataProps.samples[Math.floor(Math.random() * dataProps.samples.length)];
24 }
25}