@micromag/transforms 0.2.286
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/apple-news.js +1 -0
- package/es/apple-news.js +2157 -0
- package/es/index.js +27 -0
- package/es/utils.js +68 -0
- package/lib/apple-news.js +2186 -0
- package/lib/index.js +36 -0
- package/lib/utils.js +82 -0
- package/package.json +75 -0
- package/utils.js +1 -0
package/es/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Article } from '@micromag/transforms/apple-news';
|
|
2
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
|
+
|
|
4
|
+
var transformer = function transformer(story, type, settings) {
|
|
5
|
+
if (type === 'appleNews') {
|
|
6
|
+
return Article(story, settings);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return story;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
var postProcessor = function postProcessor(story, type) {
|
|
13
|
+
if (type === 'appleNews') {
|
|
14
|
+
var _ref = story || {},
|
|
15
|
+
components = _ref.components;
|
|
16
|
+
|
|
17
|
+
return _objectSpread(_objectSpread({}, story), {}, {
|
|
18
|
+
components: components.filter(function (c) {
|
|
19
|
+
return c !== null;
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return story;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { postProcessor, transformer };
|
package/es/utils.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
|
+
import isString from 'lodash/isString';
|
|
4
|
+
import isInteger from 'lodash/isInteger';
|
|
5
|
+
import isNumber from 'lodash/isNumber';
|
|
6
|
+
import isEmpty from 'lodash/isEmpty';
|
|
7
|
+
|
|
8
|
+
var validate = function validate() {
|
|
9
|
+
var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
|
+
var definition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
11
|
+
var validated = content ? Object.keys(content).reduce(function (values, name) {
|
|
12
|
+
var value = content[name] || null; // Find the reference
|
|
13
|
+
|
|
14
|
+
if (definition && definition.properties) {
|
|
15
|
+
var property = definition.properties.find(function (prop) {
|
|
16
|
+
return prop.name === name;
|
|
17
|
+
}) || null;
|
|
18
|
+
|
|
19
|
+
if (property !== null) {
|
|
20
|
+
var isValid = true;
|
|
21
|
+
|
|
22
|
+
switch (property.type) {
|
|
23
|
+
case 'string':
|
|
24
|
+
isValid = isString(value);
|
|
25
|
+
break;
|
|
26
|
+
|
|
27
|
+
case 'integer':
|
|
28
|
+
isValid = isInteger(value);
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case 'float':
|
|
32
|
+
isValid = isNumber(value);
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
default:
|
|
36
|
+
isValid = value !== null;
|
|
37
|
+
break;
|
|
38
|
+
} // Skip the whole thing it cause it aint gonna work
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if (!isValid && property.required) {
|
|
42
|
+
console.log('VALIDATION ERROR: SKIPPED BECAUSE REQUIRED', content, name); // eslint-disable-line
|
|
43
|
+
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (values !== null && isValid) {
|
|
48
|
+
return _objectSpread(_objectSpread({}, values), {}, _defineProperty({}, name, value));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log('VALIDATION ERROR: VALID TYPE', name, content); // eslint-disable-line
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return values;
|
|
56
|
+
}, {}) : {};
|
|
57
|
+
return !isEmpty(validated) ? validated : null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var stripTags = function stripTags(str) {
|
|
61
|
+
if (!str) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return str.replace(/(<([^>]+)>)/gi, '');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { stripTags, validate };
|