@miso.ai/doggoganger 0.9.1-beta.17 → 0.9.1-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/doggoganger-browser.min.js +1 -1
- package/package.json +11 -12
- package/rollup.config.dev.js +3 -0
- package/rollup.config.js +3 -0
- package/{rollup.util.mjs → rollup.util.js} +3 -0
- package/src/api.js +1 -1
- package/src/browser.js +1 -2
- package/src/doggoganger.js +3 -1
- package/src/middleware/latency.js +5 -5
- package/src/route/ask.js +31 -2
- package/src/route/products.js +1 -0
- package/src/route/utils.js +1 -1
- package/.github/workflows/npm-publish.yml +0 -34
- package/LICENSE +0 -21
- package/README.md +0 -2
- package/bin/data.js +0 -15
- package/bin/version.js +0 -46
- package/data/words.yaml +0 -178
- package/rollup.config.dev.mjs +0 -3
- package/rollup.config.mjs +0 -3
- package/src/api/ask.js +0 -134
- package/src/api/index.js +0 -17
- package/src/api/interactions.js +0 -13
- package/src/api/products.js +0 -28
- package/src/api/recommendation.js +0 -21
- package/src/api/search.js +0 -15
- package/src/data/answers.js +0 -53
- package/src/data/articles.js +0 -51
- package/src/data/fields.js +0 -105
- package/src/data/index.js +0 -10
- package/src/data/lorem.js +0 -145
- package/src/data/markdown/index.js +0 -304
- package/src/data/markdown/languages.js +0 -101
- package/src/data/products.js +0 -30
- package/src/data/questions.js +0 -11
- package/src/data/utils.js +0 -65
- package/src/data/words.js +0 -182
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { randomInt, imageUrl, shuffle, iterateWithLastItemSignal } from '../utils.js';
|
|
2
|
-
import * as lorem from '../lorem.js';
|
|
3
|
-
import * as languages from './languages.js';
|
|
4
|
-
|
|
5
|
-
// TODO: wild mode that generates edge cases
|
|
6
|
-
|
|
7
|
-
function extractLangFeatures(features = []) {
|
|
8
|
-
const languages = new Set();
|
|
9
|
-
const rest = [];
|
|
10
|
-
for (const feature of features) {
|
|
11
|
-
if (feature.startsWith('lang-')) {
|
|
12
|
-
let lang = feature.slice(5);
|
|
13
|
-
if (lang === 'javascript') {
|
|
14
|
-
lang = 'js';
|
|
15
|
-
}
|
|
16
|
-
languages.add(lang);
|
|
17
|
-
} else {
|
|
18
|
-
rest.push(feature);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return [[...languages], rest];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function markdown({ sources, citation, features, blocks = [8, 12], sampling = 1 } = {}) {
|
|
25
|
-
let languages = [];
|
|
26
|
-
[languages, features] = extractLangFeatures(features);
|
|
27
|
-
// TODO: block features
|
|
28
|
-
let result = sample([
|
|
29
|
-
() => atxHeading({ features }),
|
|
30
|
-
() => paragraph({ sources, citation, features }),
|
|
31
|
-
...languages.map(lang => () => fencedCodeBlock({ lang, features })),
|
|
32
|
-
...(languages.length ? [] : [() => fencedCodeBlock({ features })]),
|
|
33
|
-
() => paragraph({ sources, citation, features }),
|
|
34
|
-
() => table({ features }),
|
|
35
|
-
() => image(),
|
|
36
|
-
() => paragraph({ sources, citation, features }),
|
|
37
|
-
() => hr(),
|
|
38
|
-
() => atxHeading({ features }),
|
|
39
|
-
() => paragraph({ sources, citation, features }),
|
|
40
|
-
() => list({ features }),
|
|
41
|
-
() => paragraph({ sources, citation, features }),
|
|
42
|
-
], sampling).join('\n\n');
|
|
43
|
-
if (citation && citation.unused && citation.unused.length) {
|
|
44
|
-
// flush all unused citations
|
|
45
|
-
const indicies = [...citation.unused];
|
|
46
|
-
indicies.sort((a, b) => a - b);
|
|
47
|
-
result += indicies.map(index => _citation(citation, sources[index])).join('');
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function sample(fns, sampling) {
|
|
53
|
-
const arr = [];
|
|
54
|
-
for (const fn of fns) {
|
|
55
|
-
if (sampling >= 1 || Math.random() < sampling) {
|
|
56
|
-
arr.push(fn());
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return arr;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// leaf blocks //
|
|
63
|
-
export function hr() {
|
|
64
|
-
// wild mode: while spaces at the beginning (< 4), in between, in the end
|
|
65
|
-
// wild mode: no line break for '*'
|
|
66
|
-
return '*-_'.charAt(randomInt(0, 2)).repeat(randomInt(3, 6));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function atxHeading({ features, level = [1, 6], size = [1, 8], content }) {
|
|
70
|
-
const words = content || lorem.lorem({ size });
|
|
71
|
-
return `${'#'.repeat(randomInt(...level))} ${words}`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function setextHeading({ features, level = [1, 2], size = [1, 8], content }) {
|
|
75
|
-
const words = content || lorem.lorem({ size });
|
|
76
|
-
return `${words}\n${'=-'.charAt(randomInt(...level) - 1).repeat(3)}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function linkReferenceDefinition({ label, destination, title }) {
|
|
80
|
-
return `[${label}]: ${destination}${title !== undefined ? ` ${title}` : ''}`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function indentedCodeBlock({ lang, content, size }) {
|
|
84
|
-
content = content || codeContent({ lang, size });
|
|
85
|
-
return indent(4, content);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function fencedCodeBlock({ lang, content, size, fenceChar = '`' }) {
|
|
89
|
-
if (fenceChar === 'random') {
|
|
90
|
-
fenceChar = '`~'.charAt(randomInt(0, 1));
|
|
91
|
-
}
|
|
92
|
-
content = content || codeContent({ lang, size });
|
|
93
|
-
// TODO: escape fenceChar in content
|
|
94
|
-
return `${fenceChar.repeat(3)}${lang || ''}\n${content}\n${fenceChar.repeat(3)}`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function paragraph({ sources, citation, features, size = [20, 50] }) {
|
|
98
|
-
// force all inline features
|
|
99
|
-
const decorates = ['description', decorateInlineFeatures()];
|
|
100
|
-
if (sources && citation) {
|
|
101
|
-
decorates.push(decorateCitation(sources, citation));
|
|
102
|
-
}
|
|
103
|
-
return lorem.lorem({ size, decorates });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function table({ features, columns = [2, 4], rows = [2, 8] }) {
|
|
107
|
-
columns = randomInt(...columns);
|
|
108
|
-
rows = randomInt(...rows);
|
|
109
|
-
const defs = [...multiply({ size: 1 }, columns - 1), { size: [3, 8] }];
|
|
110
|
-
const header = lorem.lorem({ size: columns, output: 'array' });
|
|
111
|
-
const delimiter = defs.map(() => '---');
|
|
112
|
-
const body = [ header, delimiter ];
|
|
113
|
-
for (let i = 0; i < rows - 1; i++) {
|
|
114
|
-
body.push(defs.map(({ size }) => lorem.lorem({ size })));
|
|
115
|
-
}
|
|
116
|
-
return body.map(tableRow).join('\n');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function image({ url, imageSize = [400, 250], ...options } = {}) {
|
|
120
|
-
url = url || imageUrl(imageSize);
|
|
121
|
-
return ``;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// container blocks //
|
|
125
|
-
export function blockquote({ features, size = [3, 5] }) {
|
|
126
|
-
// TODO
|
|
127
|
-
return _blockquote(lorem.lorem({ size }));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const LIST_ITEM_TYPES = ['ordered', 'bullet', 'task'];
|
|
131
|
-
|
|
132
|
-
export function list({ features, type = 'random', count = [1, 8], size = [5, 15] }) {
|
|
133
|
-
count = typeof count === 'number' ? count : randomInt(...count);
|
|
134
|
-
const t = type === 'random' ? LIST_ITEM_TYPES[Math.floor(3 * Math.random())] : type;
|
|
135
|
-
const items = [];
|
|
136
|
-
while (count > 0) {
|
|
137
|
-
const c = randomInt(1, count);
|
|
138
|
-
let content = paragraph({ features, size });
|
|
139
|
-
if (c > 1) {
|
|
140
|
-
content += `\n${list({ features, type, count: c - 1, size })}`;
|
|
141
|
-
}
|
|
142
|
-
items.push(listItem(t, content));
|
|
143
|
-
count -= c;
|
|
144
|
-
}
|
|
145
|
-
return items.join('\n');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// inline //
|
|
149
|
-
export function codeSpan(options) {
|
|
150
|
-
return `\`${_content(options)}\``;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function emphasis({ level = [1, 3], options }) {
|
|
154
|
-
level = typeof level === 'number' ? level : randomInt(...level);
|
|
155
|
-
const str = '_*'.charAt(randomInt(0, 1)).repeat(level);
|
|
156
|
-
return `${str}${_content(options)}${str}`;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function link({ url = 'https://miso.ai', ...options } = {}) {
|
|
160
|
-
return `[${_content(options)}](${url})`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// TODO: ref link
|
|
164
|
-
// TODO: autolink
|
|
165
|
-
// TODO: hard line break
|
|
166
|
-
|
|
167
|
-
const INLINE_FEATURES = {
|
|
168
|
-
'code-span': () => ['`', '`'],
|
|
169
|
-
'emphasis-1': () => multiply(_emphasisAdfix(1), 2),
|
|
170
|
-
'emphasis-2': () => multiply(_emphasisAdfix(2), 2),
|
|
171
|
-
'emphasis-3': () => multiply(_emphasisAdfix(3), 2),
|
|
172
|
-
'strikethrough': () => ['~', '~'],
|
|
173
|
-
'link': ({ url = 'https://miso.ai' } = {}) => [`[`, `](${url})`],
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
function _emphasisAdfix(level = [1, 3]) {
|
|
177
|
-
level = typeof level === 'number' ? level : randomInt(...level);
|
|
178
|
-
return '_*'.charAt(randomInt(0, 1)).repeat(level);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const INLINE_FEATURE_LIST = Object.keys(INLINE_FEATURES);
|
|
182
|
-
const INLINE_FEATURE_SET = new Set(INLINE_FEATURE_LIST);
|
|
183
|
-
|
|
184
|
-
// decorator //
|
|
185
|
-
export function decorateInlineFeatures({ features = INLINE_FEATURE_LIST, size = [1, 3], rest = [0, 8] } = {}) {
|
|
186
|
-
features = features.filter(f => INLINE_FEATURE_SET.has(f));
|
|
187
|
-
|
|
188
|
-
const unused = shuffle([...features]);
|
|
189
|
-
let unusedCursor = unused.length - 1;
|
|
190
|
-
|
|
191
|
-
const rollRest = () => typeof rest === 'number' ? rest : randomInt(...rest);
|
|
192
|
-
const rollFeatureSize = () => typeof size === 'number' ? size : randomInt(...size);
|
|
193
|
-
const rollFeatureType = () => unusedCursor >= 0 ? unused[unusedCursor--] : features[randomInt(0, features.length - 1)];
|
|
194
|
-
|
|
195
|
-
return function *(iterator) {
|
|
196
|
-
let count = rollRest();
|
|
197
|
-
let suffix;
|
|
198
|
-
|
|
199
|
-
yield *iterateWithLastItemSignal(iterator, function *(word, last) {
|
|
200
|
-
// prefix if necessary
|
|
201
|
-
if (!suffix && count === 0) {
|
|
202
|
-
const [prefix, s] = INLINE_FEATURES[rollFeatureType()]();
|
|
203
|
-
word = `${prefix}${word}`;
|
|
204
|
-
count = rollFeatureSize();
|
|
205
|
-
suffix = s;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// consume word count
|
|
209
|
-
count--;
|
|
210
|
-
|
|
211
|
-
// suffix if necessary
|
|
212
|
-
if (suffix) {
|
|
213
|
-
const len = word.length;
|
|
214
|
-
const lastChar = word.charAt(len - 1);
|
|
215
|
-
if (isPunctuation(lastChar)) {
|
|
216
|
-
word = `${word.substring(0, len - 1)}${suffix}${lastChar}`;
|
|
217
|
-
suffix = undefined;
|
|
218
|
-
count = rollRest();
|
|
219
|
-
} else if (last || count === 0) {
|
|
220
|
-
word = `${word}${suffix}`;
|
|
221
|
-
suffix = undefined;
|
|
222
|
-
count = rollRest();
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// output
|
|
227
|
-
yield word;
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function decorateCitation(sources, { density = 0.667, unused, ...options }) {
|
|
233
|
-
const sourceLength = sources.length;
|
|
234
|
-
const rollIndex = () => unused && unused.length ? unused.pop() : randomInt(0, sourceLength - 1);
|
|
235
|
-
|
|
236
|
-
return function *(iterator) {
|
|
237
|
-
for (const word of iterator) {
|
|
238
|
-
// not ended with alphabet or number -> last word in sentence
|
|
239
|
-
if (word.charAt(word.length - 1) === '.' && Math.random() < density) {
|
|
240
|
-
yield `${word}${_citation(options, sources[rollIndex()])}`;
|
|
241
|
-
} else {
|
|
242
|
-
yield word;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// helper //
|
|
249
|
-
function _content({ size = [1, 3], content } = {}) {
|
|
250
|
-
return content || lorem.lorem({ size });
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function _blockquote(content) {
|
|
254
|
-
return content.split('\n').map(line => `> ${line}`).join('\n');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export function indent(size, content) {
|
|
258
|
-
return content.split('\n').map(line => ' '.repeat(size) + line).join('\n');
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export function listItem(type, content) {
|
|
262
|
-
const [firstLine, restLines] = content.split('\n', 2);
|
|
263
|
-
const result = `${listItemPrefix(type)} ${firstLine}`;
|
|
264
|
-
const indentSize = type === 'ordered' ? 3 : 2;
|
|
265
|
-
return !restLines ? result : result + `\n${indent(indentSize, restLines)}`;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function listItemPrefix(type, checked = 'random') {
|
|
269
|
-
switch (type) {
|
|
270
|
-
case 'ordered':
|
|
271
|
-
return '1.';
|
|
272
|
-
case 'bullet':
|
|
273
|
-
return '-';
|
|
274
|
-
case 'task':
|
|
275
|
-
const mark = (checked === 'random' ? Math.random() < 0.5 : !!checked) ? 'x' : ' ';
|
|
276
|
-
return `- [${mark}]`;
|
|
277
|
-
default:
|
|
278
|
-
throw new Error(`unknown list item type: ${type}`);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function codeContent({ lang, size = [10, 30] }) {
|
|
283
|
-
return lang && languages[lang] ? languages[lang]() : lorem.lorem({ output: 'multiline', size });
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function tableRow(cells) {
|
|
287
|
-
return `| ${cells.join(' | ')} |`;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function multiply(obj, i) {
|
|
291
|
-
const arr = [];
|
|
292
|
-
for (let j = 0; j < i; j++) {
|
|
293
|
-
arr.push(typeof obj === 'function' ? obj() : obj);
|
|
294
|
-
}
|
|
295
|
-
return arr;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function isPunctuation(char) {
|
|
299
|
-
return char === '.' || char === ',' || char === '!' || char === '?' || char === ':' || char === ';';
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function _citation({ link, start, end }, { index, url }) {
|
|
303
|
-
return link ? `[${start}${index}${end}](${url})` : `${start}${index}${end}`;
|
|
304
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
export function javascript() {
|
|
2
|
-
return JAVASCRIPT;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function js() {
|
|
6
|
-
return JAVASCRIPT;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const JAVASCRIPT = `
|
|
10
|
-
// module
|
|
11
|
-
import { a, b } from './module';
|
|
12
|
-
import * as module from './module';
|
|
13
|
-
import module from './module';
|
|
14
|
-
export default module;
|
|
15
|
-
export const a = 0;
|
|
16
|
-
export * from './module';
|
|
17
|
-
export * as module from './module';
|
|
18
|
-
|
|
19
|
-
// variables
|
|
20
|
-
let a = 10;
|
|
21
|
-
const b = 20;
|
|
22
|
-
|
|
23
|
-
// function declaration
|
|
24
|
-
function sum(x, y) {
|
|
25
|
-
return x + y;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// generator function
|
|
29
|
-
function* iterator() {
|
|
30
|
-
yield 0;
|
|
31
|
-
yield 1;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// arrow function
|
|
35
|
-
const multiply = (x, y) => x * y;
|
|
36
|
-
|
|
37
|
-
// class
|
|
38
|
-
class Person {
|
|
39
|
-
constructor(name, age) {
|
|
40
|
-
this.name = name;
|
|
41
|
-
this.age = age;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
greet() {
|
|
45
|
-
console.log('Hello, my name is Miso.');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// primitive
|
|
50
|
-
const str = 'Hello, world!';
|
|
51
|
-
const num = 10.99;
|
|
52
|
-
|
|
53
|
-
// object
|
|
54
|
-
const person = new Person('John', 30);
|
|
55
|
-
person.greet();
|
|
56
|
-
|
|
57
|
-
// object literal
|
|
58
|
-
const object = {
|
|
59
|
-
name: 'John',
|
|
60
|
-
[x]: 10,
|
|
61
|
-
...props,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// array literal
|
|
65
|
-
const arr = [1, 2, 3, 4, 5, ...props];
|
|
66
|
-
|
|
67
|
-
// regexp literal
|
|
68
|
-
const regexp = /\\w+/g;
|
|
69
|
-
|
|
70
|
-
// operators
|
|
71
|
-
const sum = a + b;
|
|
72
|
-
const product = a * b;
|
|
73
|
-
const negation = -a;
|
|
74
|
-
const max = a > b ? a : b;
|
|
75
|
-
|
|
76
|
-
// flow control
|
|
77
|
-
let i = 9;
|
|
78
|
-
for (const n of arr) {
|
|
79
|
-
if (n > i) {
|
|
80
|
-
console.log(n);
|
|
81
|
-
}
|
|
82
|
-
i++;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// async/await
|
|
86
|
-
(async () => {
|
|
87
|
-
const result = await asyncFunction();
|
|
88
|
-
})();
|
|
89
|
-
|
|
90
|
-
// try/catch
|
|
91
|
-
try {
|
|
92
|
-
} catch (e) {
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// destructuring
|
|
96
|
-
const { name, age, ...rest } = person;
|
|
97
|
-
const [ x, y, ...rest ] = arr;
|
|
98
|
-
|
|
99
|
-
// template literals
|
|
100
|
-
${'console.log(`The sum of ${a} and ${b} is ${sum(a, b)}.`);'}
|
|
101
|
-
`.trim();
|
package/src/data/products.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as u from './utils.js';
|
|
2
|
-
import * as fields from './fields.js';
|
|
3
|
-
|
|
4
|
-
export function *products({ rows, ...options } = {}) {
|
|
5
|
-
for (let i = 0; i < rows; i++) {
|
|
6
|
-
yield product({ ...options, index: i });
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function product({} = {}) {
|
|
11
|
-
const id = u.id();
|
|
12
|
-
const prices = u.repeat(fields.price, [1, 2]);
|
|
13
|
-
prices.sort();
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
product_id: id,
|
|
17
|
-
authors: fields.authors(),
|
|
18
|
-
categories: [],
|
|
19
|
-
tags: fields.tags(),
|
|
20
|
-
title: fields.title(),
|
|
21
|
-
description: fields.description(),
|
|
22
|
-
//html,
|
|
23
|
-
cover_image: fields.image(),
|
|
24
|
-
url: `https://dummy.miso.ai/products/${id}`,
|
|
25
|
-
sale_price: prices[0],
|
|
26
|
-
original_price: prices[prices.length - 1],
|
|
27
|
-
rating: fields.rating(),
|
|
28
|
-
availability: fields.availability(),
|
|
29
|
-
};
|
|
30
|
-
}
|
package/src/data/questions.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as fields from './fields.js';
|
|
2
|
-
|
|
3
|
-
export function *questions({ rows = 5, ...options } = {}) {
|
|
4
|
-
for (let i = 0; i < rows; i++) {
|
|
5
|
-
yield question({ ...options, index: i });
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function question({} = {}) {
|
|
10
|
-
return fields.description({ size: [4, 8], punctuation: '?' });
|
|
11
|
-
}
|
package/src/data/utils.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export function uuid() {
|
|
2
|
-
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, a => (a ^ Math.random() * 16 >> a / 4).toString(16));
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function randomInt(min, max) {
|
|
6
|
-
return max == null || (max <= min) ? min : (min + Math.floor(Math.random() * (max - min + 1)));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// TODO: pass in size
|
|
10
|
-
export function repeat(fn, range) {
|
|
11
|
-
const n = randomInt(...range);
|
|
12
|
-
const result = [];
|
|
13
|
-
for (let i = 0; i < n; i++) {
|
|
14
|
-
result.push(fn());
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function id() {
|
|
20
|
-
return Math.random().toString(36).substring(2, 10);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function shuffle(array) {
|
|
24
|
-
for (let i = array.length - 1; i > 0; i--) {
|
|
25
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
26
|
-
[array[i], array[j]] = [array[j], array[i]];
|
|
27
|
-
}
|
|
28
|
-
return array;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function imageUrl(size) {
|
|
32
|
-
const seed = Math.floor(Math.random() * 1000);
|
|
33
|
-
const sizePath = Array.isArray(size) ? size.length > 1 ? `${size[0]}/${size[1]}` : `${size[0]}` : `${size}`;
|
|
34
|
-
return `https://picsum.photos/seed/${seed}/${sizePath}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function formatDatetime(timestamp) {
|
|
38
|
-
const str = new Date(timestamp).toISOString();
|
|
39
|
-
return str.endsWith('Z') ? str.slice(0, -1) : str;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function sample(size, sampling) {
|
|
43
|
-
return sampling !== undefined ? Math.ceil(size * sampling) : size;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function gaussRandom() {
|
|
47
|
-
return uniformRandom() + uniformRandom() + uniformRandom();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function uniformRandom() {
|
|
51
|
-
return Math.random() * 2 - 1;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function *iterateWithLastItemSignal(iterator, fn) {
|
|
55
|
-
let last;
|
|
56
|
-
for (const item of iterator) {
|
|
57
|
-
if (last) {
|
|
58
|
-
yield* fn(last);
|
|
59
|
-
}
|
|
60
|
-
last = item;
|
|
61
|
-
}
|
|
62
|
-
if (last) {
|
|
63
|
-
yield* fn(last, true);
|
|
64
|
-
}
|
|
65
|
-
}
|
package/src/data/words.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// genereated by bin/data.js
|
|
3
|
-
export default [
|
|
4
|
-
"lorem",
|
|
5
|
-
"ipsum",
|
|
6
|
-
"dolor",
|
|
7
|
-
"sit",
|
|
8
|
-
"amet",
|
|
9
|
-
"consectetur",
|
|
10
|
-
"adipiscing",
|
|
11
|
-
"elit",
|
|
12
|
-
"curabitur",
|
|
13
|
-
"vel",
|
|
14
|
-
"hendrerit",
|
|
15
|
-
"libero",
|
|
16
|
-
"eleifend",
|
|
17
|
-
"blandit",
|
|
18
|
-
"nunc",
|
|
19
|
-
"ornare",
|
|
20
|
-
"odio",
|
|
21
|
-
"ut",
|
|
22
|
-
"orci",
|
|
23
|
-
"gravida",
|
|
24
|
-
"imperdiet",
|
|
25
|
-
"nullam",
|
|
26
|
-
"purus",
|
|
27
|
-
"lacinia",
|
|
28
|
-
"a",
|
|
29
|
-
"pretium",
|
|
30
|
-
"quis",
|
|
31
|
-
"congue",
|
|
32
|
-
"praesent",
|
|
33
|
-
"sagittis",
|
|
34
|
-
"laoreet",
|
|
35
|
-
"auctor",
|
|
36
|
-
"mauris",
|
|
37
|
-
"non",
|
|
38
|
-
"velit",
|
|
39
|
-
"eros",
|
|
40
|
-
"dictum",
|
|
41
|
-
"proin",
|
|
42
|
-
"accumsan",
|
|
43
|
-
"sapien",
|
|
44
|
-
"nec",
|
|
45
|
-
"massa",
|
|
46
|
-
"volutpat",
|
|
47
|
-
"venenatis",
|
|
48
|
-
"sed",
|
|
49
|
-
"eu",
|
|
50
|
-
"molestie",
|
|
51
|
-
"lacus",
|
|
52
|
-
"quisque",
|
|
53
|
-
"porttitor",
|
|
54
|
-
"ligula",
|
|
55
|
-
"dui",
|
|
56
|
-
"mollis",
|
|
57
|
-
"tempus",
|
|
58
|
-
"at",
|
|
59
|
-
"magna",
|
|
60
|
-
"vestibulum",
|
|
61
|
-
"turpis",
|
|
62
|
-
"ac",
|
|
63
|
-
"diam",
|
|
64
|
-
"tincidunt",
|
|
65
|
-
"id",
|
|
66
|
-
"condimentum",
|
|
67
|
-
"enim",
|
|
68
|
-
"sodales",
|
|
69
|
-
"in",
|
|
70
|
-
"hac",
|
|
71
|
-
"habitasse",
|
|
72
|
-
"platea",
|
|
73
|
-
"dictumst",
|
|
74
|
-
"aenean",
|
|
75
|
-
"neque",
|
|
76
|
-
"fusce",
|
|
77
|
-
"augue",
|
|
78
|
-
"leo",
|
|
79
|
-
"eget",
|
|
80
|
-
"semper",
|
|
81
|
-
"mattis",
|
|
82
|
-
"tortor",
|
|
83
|
-
"scelerisque",
|
|
84
|
-
"nulla",
|
|
85
|
-
"interdum",
|
|
86
|
-
"tellus",
|
|
87
|
-
"malesuada",
|
|
88
|
-
"rhoncus",
|
|
89
|
-
"porta",
|
|
90
|
-
"sem",
|
|
91
|
-
"aliquet",
|
|
92
|
-
"et",
|
|
93
|
-
"nam",
|
|
94
|
-
"suspendisse",
|
|
95
|
-
"potenti",
|
|
96
|
-
"vivamus",
|
|
97
|
-
"luctus",
|
|
98
|
-
"fringilla",
|
|
99
|
-
"erat",
|
|
100
|
-
"donec",
|
|
101
|
-
"justo",
|
|
102
|
-
"vehicula",
|
|
103
|
-
"ultricies",
|
|
104
|
-
"varius",
|
|
105
|
-
"ante",
|
|
106
|
-
"primis",
|
|
107
|
-
"faucibus",
|
|
108
|
-
"ultrices",
|
|
109
|
-
"posuere",
|
|
110
|
-
"cubilia",
|
|
111
|
-
"curae",
|
|
112
|
-
"etiam",
|
|
113
|
-
"cursus",
|
|
114
|
-
"aliquam",
|
|
115
|
-
"quam",
|
|
116
|
-
"dapibus",
|
|
117
|
-
"nisl",
|
|
118
|
-
"feugiat",
|
|
119
|
-
"egestas",
|
|
120
|
-
"class",
|
|
121
|
-
"aptent",
|
|
122
|
-
"taciti",
|
|
123
|
-
"sociosqu",
|
|
124
|
-
"ad",
|
|
125
|
-
"litora",
|
|
126
|
-
"torquent",
|
|
127
|
-
"per",
|
|
128
|
-
"conubia",
|
|
129
|
-
"nostra",
|
|
130
|
-
"inceptos",
|
|
131
|
-
"himenaeos",
|
|
132
|
-
"phasellus",
|
|
133
|
-
"nibh",
|
|
134
|
-
"pulvinar",
|
|
135
|
-
"vitae",
|
|
136
|
-
"urna",
|
|
137
|
-
"iaculis",
|
|
138
|
-
"lobortis",
|
|
139
|
-
"nisi",
|
|
140
|
-
"viverra",
|
|
141
|
-
"arcu",
|
|
142
|
-
"morbi",
|
|
143
|
-
"pellentesque",
|
|
144
|
-
"metus",
|
|
145
|
-
"commodo",
|
|
146
|
-
"ut",
|
|
147
|
-
"facilisis",
|
|
148
|
-
"felis",
|
|
149
|
-
"tristique",
|
|
150
|
-
"ullamcorper",
|
|
151
|
-
"placerat",
|
|
152
|
-
"aenean",
|
|
153
|
-
"convallis",
|
|
154
|
-
"sollicitudin",
|
|
155
|
-
"integer",
|
|
156
|
-
"rutrum",
|
|
157
|
-
"duis",
|
|
158
|
-
"est",
|
|
159
|
-
"etiam",
|
|
160
|
-
"bibendum",
|
|
161
|
-
"donec",
|
|
162
|
-
"pharetra",
|
|
163
|
-
"vulputate",
|
|
164
|
-
"maecenas",
|
|
165
|
-
"mi",
|
|
166
|
-
"fermentum",
|
|
167
|
-
"consequat",
|
|
168
|
-
"suscipit",
|
|
169
|
-
"aliquam",
|
|
170
|
-
"habitant",
|
|
171
|
-
"senectus",
|
|
172
|
-
"netus",
|
|
173
|
-
"fames",
|
|
174
|
-
"quisque",
|
|
175
|
-
"euismod",
|
|
176
|
-
"curabitur",
|
|
177
|
-
"lectus",
|
|
178
|
-
"elementum",
|
|
179
|
-
"tempor",
|
|
180
|
-
"risus",
|
|
181
|
-
"cras"
|
|
182
|
-
];
|