UNPKG

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