Last change
on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
801 bytes
|
Line | |
---|
1 | function iterateProps(obj, iterator) {
|
---|
2 | Object.keys(obj).forEach(key => iterator({ ...obj[key], name: key }));
|
---|
3 | }
|
---|
4 |
|
---|
5 | function mapProps(obj) {
|
---|
6 | return Object.keys(obj).map(key => ({ ...obj[key], name: key }));
|
---|
7 | }
|
---|
8 |
|
---|
9 | function filterProps(obj, filter) {
|
---|
10 | const ret = {};
|
---|
11 | Object.keys(obj).forEach(key => {
|
---|
12 | if (filter(obj[key])) {
|
---|
13 | ret[key] = obj[key];
|
---|
14 | }
|
---|
15 | });
|
---|
16 | return ret;
|
---|
17 | }
|
---|
18 |
|
---|
19 | function typeSignature(meta) {
|
---|
20 | const type = meta.array ? `Array<${meta.type}>` : meta.type;
|
---|
21 | if (meta.optional) {
|
---|
22 | return `${meta.name}?: ${type}`;
|
---|
23 | } else if (meta.maybe) {
|
---|
24 | return `${meta.name}: ?${type}`;
|
---|
25 | } else {
|
---|
26 | return `${meta.name}: ${type}`;
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | const unique = items => Array.from(new Set(items));
|
---|
31 |
|
---|
32 | module.exports = {
|
---|
33 | iterateProps,
|
---|
34 | mapProps,
|
---|
35 | filterProps,
|
---|
36 | typeSignature,
|
---|
37 | unique
|
---|
38 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.