@maizzle/framework 4.0.0-alpha.9 → 4.0.2

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.
Files changed (70) hide show
  1. package/.editorconfig +9 -9
  2. package/.github/media/logo-dark.svg +1 -0
  3. package/.github/media/logo-light.svg +1 -0
  4. package/.github/workflows/nodejs.yml +28 -28
  5. package/LICENSE +21 -21
  6. package/README.md +42 -35
  7. package/bin/maizzle +3 -3
  8. package/package.json +91 -91
  9. package/src/generators/config.js +32 -32
  10. package/src/generators/output/index.js +4 -4
  11. package/src/generators/output/to-disk.js +208 -208
  12. package/src/generators/output/to-string.js +1 -5
  13. package/src/generators/postcss.js +29 -29
  14. package/src/generators/posthtml.js +66 -66
  15. package/src/index.js +17 -17
  16. package/src/transformers/attributeToStyle.js +90 -90
  17. package/src/transformers/baseUrl.js +69 -69
  18. package/src/transformers/extraAttributes.js +26 -26
  19. package/src/transformers/filters/defaultFilters.js +126 -126
  20. package/src/transformers/filters/index.js +55 -55
  21. package/src/transformers/index.js +63 -60
  22. package/src/transformers/inlineCss.js +37 -50
  23. package/src/transformers/markdown.js +19 -19
  24. package/src/transformers/minify.js +21 -21
  25. package/src/transformers/plaintext.js +23 -23
  26. package/src/transformers/posthtmlMso.js +10 -10
  27. package/src/transformers/prettify.js +9 -11
  28. package/src/transformers/preventWidows.js +13 -13
  29. package/src/transformers/removeAttributes.js +17 -17
  30. package/src/transformers/removeInlineBackgroundColor.js +52 -52
  31. package/src/transformers/removeInlineSizes.js +41 -41
  32. package/src/transformers/replaceStrings.js +14 -14
  33. package/src/transformers/safeClassNames.js +24 -24
  34. package/src/transformers/shorthandInlineCSS.js +19 -0
  35. package/src/transformers/sixHex.js +33 -33
  36. package/src/transformers/urlParameters.js +17 -17
  37. package/src/utils/helpers.js +17 -17
  38. package/test/expected/posthtml/component.html +1 -1
  39. package/test/expected/posthtml/extend-template.html +2 -2
  40. package/test/expected/posthtml/fetch.html +5 -5
  41. package/test/expected/posthtml/layout.html +3 -3
  42. package/test/expected/transformers/atimport-in-style.html +12 -13
  43. package/test/expected/transformers/base-url.html +99 -99
  44. package/test/expected/transformers/preserve-transform-css.html +33 -45
  45. package/test/expected/useConfig.html +6 -6
  46. package/test/fixtures/posthtml/component.html +2 -2
  47. package/test/fixtures/posthtml/extend-template.html +7 -7
  48. package/test/fixtures/posthtml/fetch.html +9 -9
  49. package/test/fixtures/posthtml/layout.html +11 -11
  50. package/test/fixtures/transformers/base-url.html +101 -101
  51. package/test/stubs/assets/foo.bar +1 -1
  52. package/test/stubs/breaking/bad.html +5 -5
  53. package/test/stubs/config/config.js +10 -10
  54. package/test/stubs/config/config.maizzle-ci.js +10 -10
  55. package/test/stubs/data.json +14 -14
  56. package/test/stubs/events/before-create.html +1 -1
  57. package/test/stubs/layouts/basic.html +1 -1
  58. package/test/stubs/layouts/full.html +12 -12
  59. package/test/stubs/layouts/template.html +5 -5
  60. package/test/stubs/main.css +5 -5
  61. package/test/stubs/tailwind/content-source.html +1 -1
  62. package/test/stubs/tailwind/tailwind.css +3 -3
  63. package/test/stubs/template.html +10 -10
  64. package/test/test-config.js +19 -19
  65. package/test/test-postcss.js +8 -8
  66. package/test/test-posthtml.js +17 -11
  67. package/test/test-tailwindcss.js +117 -117
  68. package/test/test-todisk.js +1 -1
  69. package/test/test-transformers.js +511 -490
  70. package/xo.config.js +22 -22
@@ -1,90 +1,90 @@
1
- const posthtml = require('posthtml')
2
- const parseAttrs = require('posthtml-attrs-parser')
3
- const {get, forEach, intersection, keys, isEmpty} = require('lodash')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
7
- const attributes = get(config, 'inlineCSS.attributeToStyle', false)
8
-
9
- if (typeof attributes === 'boolean' && attributes) {
10
- return posthtml([attributesToStyle()]).process(html, posthtmlOptions).then(result => result.html)
11
- }
12
-
13
- if (Array.isArray(attributes) && !isEmpty(attributes)) {
14
- return posthtml([attributesToStyle({attributes})]).process(html, posthtmlOptions).then(result => result.html)
15
- }
16
-
17
- if (direct) {
18
- return posthtml([
19
- attributesToStyle({
20
- attributes: Array.isArray(config) ? config : []
21
- })
22
- ]).process(html).then(result => result.html)
23
- }
24
-
25
- return html
26
- }
27
-
28
- const attributesToStyle = (options = {}) => tree => {
29
- options.attributes = options.attributes || ['width', 'height', 'bgcolor', 'background', 'align', 'valign']
30
-
31
- const process = node => {
32
- const nodeAttributes = parseAttrs(node.attrs)
33
- const matches = intersection(keys(nodeAttributes), options.attributes)
34
- const nodeStyle = get(node.attrs, 'style')
35
- const csstoInline = []
36
-
37
- forEach(matches, attribute => {
38
- let value = get(node.attrs, attribute)
39
-
40
- switch (attribute) {
41
- case 'bgcolor':
42
- csstoInline.push(`background-color: ${value}`)
43
- break
44
-
45
- case 'background':
46
- csstoInline.push(`background-image: url('${value}')`)
47
- break
48
-
49
- case 'width':
50
- value = Number.parseInt(value, 10) + (value.match(/px|%/) || 'px')
51
- csstoInline.push(`width: ${value}`)
52
- break
53
-
54
- case 'height':
55
- value = Number.parseInt(value, 10) + (value.match(/px|%/) || 'px')
56
- csstoInline.push(`height: ${value}`)
57
- break
58
-
59
- case 'align':
60
- if (node.tag !== 'table') {
61
- return csstoInline.push(`text-align: ${value}`)
62
- }
63
-
64
- if (['left', 'right'].includes(value)) {
65
- csstoInline.push(`float: ${value}`)
66
- }
67
-
68
- if (value === 'center') {
69
- csstoInline.push('margin-left: auto', 'margin-right: auto')
70
- }
71
-
72
- break
73
-
74
- case 'valign':
75
- csstoInline.push(`vertical-align: ${value}`)
76
- break
77
-
78
- // No default
79
- }
80
- })
81
-
82
- nodeAttributes.style = nodeStyle ? `${nodeStyle} ${csstoInline.join('; ')}` : `${csstoInline.join('; ')}`
83
-
84
- node.attrs = nodeAttributes.compose()
85
-
86
- return node
87
- }
88
-
89
- return tree.walk(process)
90
- }
1
+ const posthtml = require('posthtml')
2
+ const parseAttrs = require('posthtml-attrs-parser')
3
+ const {get, forEach, intersection, keys, isEmpty} = require('lodash')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
7
+ const attributes = get(config, 'inlineCSS.attributeToStyle', false)
8
+
9
+ if (typeof attributes === 'boolean' && attributes) {
10
+ return posthtml([attributesToStyle()]).process(html, posthtmlOptions).then(result => result.html)
11
+ }
12
+
13
+ if (Array.isArray(attributes) && !isEmpty(attributes)) {
14
+ return posthtml([attributesToStyle({attributes})]).process(html, posthtmlOptions).then(result => result.html)
15
+ }
16
+
17
+ if (direct) {
18
+ return posthtml([
19
+ attributesToStyle({
20
+ attributes: Array.isArray(config) ? config : []
21
+ })
22
+ ]).process(html).then(result => result.html)
23
+ }
24
+
25
+ return html
26
+ }
27
+
28
+ const attributesToStyle = (options = {}) => tree => {
29
+ options.attributes = options.attributes || ['width', 'height', 'bgcolor', 'background', 'align', 'valign']
30
+
31
+ const process = node => {
32
+ const nodeAttributes = parseAttrs(node.attrs)
33
+ const matches = intersection(keys(nodeAttributes), options.attributes)
34
+ const nodeStyle = get(node.attrs, 'style')
35
+ const csstoInline = []
36
+
37
+ forEach(matches, attribute => {
38
+ let value = get(node.attrs, attribute)
39
+
40
+ switch (attribute) {
41
+ case 'bgcolor':
42
+ csstoInline.push(`background-color: ${value}`)
43
+ break
44
+
45
+ case 'background':
46
+ csstoInline.push(`background-image: url('${value}')`)
47
+ break
48
+
49
+ case 'width':
50
+ value = Number.parseInt(value, 10) + (value.match(/px|%/) || 'px')
51
+ csstoInline.push(`width: ${value}`)
52
+ break
53
+
54
+ case 'height':
55
+ value = Number.parseInt(value, 10) + (value.match(/px|%/) || 'px')
56
+ csstoInline.push(`height: ${value}`)
57
+ break
58
+
59
+ case 'align':
60
+ if (node.tag !== 'table') {
61
+ return csstoInline.push(`text-align: ${value}`)
62
+ }
63
+
64
+ if (['left', 'right'].includes(value)) {
65
+ csstoInline.push(`float: ${value}`)
66
+ }
67
+
68
+ if (value === 'center') {
69
+ csstoInline.push('margin-left: auto', 'margin-right: auto')
70
+ }
71
+
72
+ break
73
+
74
+ case 'valign':
75
+ csstoInline.push(`vertical-align: ${value}`)
76
+ break
77
+
78
+ // No default
79
+ }
80
+ })
81
+
82
+ nodeAttributes.style = nodeStyle ? `${nodeStyle} ${csstoInline.join('; ')}` : `${csstoInline.join('; ')}`
83
+
84
+ node.attrs = nodeAttributes.compose()
85
+
86
+ return node
87
+ }
88
+
89
+ return tree.walk(process)
90
+ }
@@ -1,69 +1,69 @@
1
- const posthtml = require('posthtml')
2
- const isUrl = require('is-url-superb')
3
- const baseUrl = require('posthtml-base-url')
4
- const {get, isObject, isEmpty} = require('lodash')
5
-
6
- /**
7
- * VML backgrounds must be handled with regex because
8
- * they're inside HTML comments.
9
- */
10
- const rewriteVMLs = (html, url) => {
11
- // Handle <v:image>
12
- const vImageMatches = html.match(/<v:image[^>]+src="?([^"\s]+)"/g)
13
-
14
- if (vImageMatches) {
15
- vImageMatches.forEach(match => {
16
- const vImage = match.match(/<v:image[^>]+src="?([^"\s]+)"/)
17
- const vImageSrc = vImage[1]
18
-
19
- if (!isUrl(vImageSrc)) {
20
- const vImageSrcUrl = url + vImageSrc
21
- const vImageReplace = vImage[0].replace(vImageSrc, vImageSrcUrl)
22
- html = html.replace(vImage[0], vImageReplace)
23
- }
24
- })
25
- }
26
-
27
- // Handle <v:fill>
28
- const vFillMatches = html.match(/<v:fill[^>]+src="?([^"\s]+)"/g)
29
-
30
- if (vFillMatches) {
31
- vFillMatches.forEach(match => {
32
- const vFill = match.match(/<v:fill[^>]+src="?([^"\s]+)"/)
33
- const vFillSrc = vFill[1]
34
-
35
- if (!isUrl(vFillSrc)) {
36
- const vFillSrcUrl = url + vFillSrc
37
- const vFillReplace = vFill[0].replace(vFillSrc, vFillSrcUrl)
38
- html = html.replace(vFill[0], vFillReplace)
39
- }
40
- })
41
- }
42
-
43
- return html
44
- }
45
-
46
- module.exports = async (html, config = {}, direct = false) => {
47
- const url = direct ? config : get(config, 'baseURL')
48
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
49
-
50
- // Handle `baseUrl` as a string
51
- if (typeof url === 'string' && url.length > 0) {
52
- html = rewriteVMLs(html, url)
53
-
54
- return posthtml([
55
- baseUrl({url, allTags: true, styleTag: true, inlineCss: true})
56
- ])
57
- .process(html, posthtmlOptions)
58
- .then(result => result.html)
59
- }
60
-
61
- // Handle `baseUrl` as an object
62
- if (isObject(url) && !isEmpty(url)) {
63
- html = rewriteVMLs(html, url.url)
64
-
65
- return posthtml([baseUrl(url)]).process(html, posthtmlOptions).then(result => result.html)
66
- }
67
-
68
- return html
69
- }
1
+ const posthtml = require('posthtml')
2
+ const isUrl = require('is-url-superb')
3
+ const baseUrl = require('posthtml-base-url')
4
+ const {get, isObject, isEmpty} = require('lodash')
5
+
6
+ /**
7
+ * VML backgrounds must be handled with regex because
8
+ * they're inside HTML comments.
9
+ */
10
+ const rewriteVMLs = (html, url) => {
11
+ // Handle <v:image>
12
+ const vImageMatches = html.match(/<v:image[^>]+src="?([^"\s]+)"/g)
13
+
14
+ if (vImageMatches) {
15
+ vImageMatches.forEach(match => {
16
+ const vImage = match.match(/<v:image[^>]+src="?([^"\s]+)"/)
17
+ const vImageSrc = vImage[1]
18
+
19
+ if (!isUrl(vImageSrc)) {
20
+ const vImageSrcUrl = url + vImageSrc
21
+ const vImageReplace = vImage[0].replace(vImageSrc, vImageSrcUrl)
22
+ html = html.replace(vImage[0], vImageReplace)
23
+ }
24
+ })
25
+ }
26
+
27
+ // Handle <v:fill>
28
+ const vFillMatches = html.match(/<v:fill[^>]+src="?([^"\s]+)"/g)
29
+
30
+ if (vFillMatches) {
31
+ vFillMatches.forEach(match => {
32
+ const vFill = match.match(/<v:fill[^>]+src="?([^"\s]+)"/)
33
+ const vFillSrc = vFill[1]
34
+
35
+ if (!isUrl(vFillSrc)) {
36
+ const vFillSrcUrl = url + vFillSrc
37
+ const vFillReplace = vFill[0].replace(vFillSrc, vFillSrcUrl)
38
+ html = html.replace(vFill[0], vFillReplace)
39
+ }
40
+ })
41
+ }
42
+
43
+ return html
44
+ }
45
+
46
+ module.exports = async (html, config = {}, direct = false) => {
47
+ const url = direct ? config : get(config, 'baseURL')
48
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
49
+
50
+ // Handle `baseUrl` as a string
51
+ if (typeof url === 'string' && url.length > 0) {
52
+ html = rewriteVMLs(html, url)
53
+
54
+ return posthtml([
55
+ baseUrl({url, allTags: true, styleTag: true, inlineCss: true})
56
+ ])
57
+ .process(html, posthtmlOptions)
58
+ .then(result => result.html)
59
+ }
60
+
61
+ // Handle `baseUrl` as an object
62
+ if (isObject(url) && !isEmpty(url)) {
63
+ html = rewriteVMLs(html, url.url)
64
+
65
+ return posthtml([baseUrl(url)]).process(html, posthtmlOptions).then(result => result.html)
66
+ }
67
+
68
+ return html
69
+ }
@@ -1,26 +1,26 @@
1
- const posthtml = require('posthtml')
2
- const {get, isObject} = require('lodash')
3
- const addAttributes = require('posthtml-extra-attributes')
4
-
5
- module.exports = async (html, config = {}, direct = false) => {
6
- if (get(config, 'extraAttributes') === false) {
7
- return html
8
- }
9
-
10
- const posthtmlOptions = get(config, 'build.posthtml.options', {})
11
-
12
- let attributes = {
13
- table: {
14
- cellpadding: 0,
15
- cellspacing: 0,
16
- role: 'presentation'
17
- },
18
- img: {
19
- alt: ''
20
- }
21
- }
22
-
23
- attributes = direct ? {...attributes, ...config} : (isObject(config.extraAttributes) ? {...attributes, ...config.extraAttributes} : attributes)
24
-
25
- return posthtml([addAttributes({attributes})]).process(html, posthtmlOptions).then(result => result.html)
26
- }
1
+ const posthtml = require('posthtml')
2
+ const {get, isObject} = require('lodash')
3
+ const addAttributes = require('posthtml-extra-attributes')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ if (get(config, 'extraAttributes') === false) {
7
+ return html
8
+ }
9
+
10
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
11
+
12
+ let attributes = {
13
+ table: {
14
+ cellpadding: 0,
15
+ cellspacing: 0,
16
+ role: 'presentation'
17
+ },
18
+ img: {
19
+ alt: ''
20
+ }
21
+ }
22
+
23
+ attributes = direct ? {...attributes, ...config} : (isObject(config.extraAttributes) ? {...attributes, ...config.extraAttributes} : attributes)
24
+
25
+ return posthtml([addAttributes({attributes})]).process(html, posthtmlOptions).then(result => result.html)
26
+ }
@@ -1,126 +1,126 @@
1
- const escapeMap = {
2
- '&': '&amp;',
3
- '<': '&lt;',
4
- '>': '&gt;',
5
- '"': '&#34;',
6
- '\'': '&#39;'
7
- }
8
-
9
- const unescapeMap = {
10
- '&amp;': '&',
11
- '&lt;': '<',
12
- '&gt;': '>',
13
- '&#34;': '"',
14
- '&#39;': '\''
15
- }
16
-
17
- const unescape = string => string.replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m])
18
-
19
- const append = (content, attribute) => content + attribute
20
- const capitalize = content => content.charAt(0).toUpperCase() + content.slice(1)
21
- const ceil = content => Math.ceil(Number.parseFloat(content))
22
- const divide = (content, attribute) => Number.parseFloat(content) / Number.parseFloat(attribute)
23
- const escape = content => content.replace(/["&'<>]/g, m => escapeMap[m])
24
- const escapeOnce = content => escape(unescape(content))
25
- const floor = content => Math.floor(Number.parseFloat(content))
26
- const lowercase = content => content.toLowerCase()
27
- const lstrip = content => content.replace(/^\s+/, '')
28
- const minus = (content, attribute) => Number.parseFloat(content) - Number.parseFloat(attribute)
29
- const modulo = (content, attribute) => Number.parseFloat(content) % Number.parseFloat(attribute)
30
- const multiply = (content, attribute) => Number.parseFloat(content) * Number.parseFloat(attribute)
31
- const newlineToBr = content => content.replace(/\n/g, '<br>')
32
- const plus = (content, attribute) => Number.parseFloat(content) + Number.parseFloat(attribute)
33
- const prepend = (content, attribute) => attribute + content
34
-
35
- const remove = (content, attribute) => {
36
- const regex = new RegExp(attribute, 'g')
37
- return content.replace(regex, '')
38
- }
39
-
40
- const removeFirst = (content, attribute) => content.replace(attribute, '')
41
- const replace = (content, attribute) => {
42
- const [search, replace] = attribute.split('|')
43
- const regex = new RegExp(search, 'g')
44
- return content.replace(regex, replace)
45
- }
46
-
47
- const replaceFirst = (content, attribute) => {
48
- const [search, replace] = attribute.split('|')
49
- return content.replace(search, replace)
50
- }
51
-
52
- const round = content => Math.round(Number.parseFloat(content))
53
- const rstrip = content => content.replace(/\s+$/, '')
54
- const uppercase = content => content.toUpperCase()
55
- const size = content => content.length
56
- const slice = (content, attribute) => {
57
- try {
58
- const [start, end] = attribute.split(',')
59
- return content.slice(start, end)
60
- } catch {
61
- return content.slice(attribute)
62
- }
63
- }
64
-
65
- const stripNewlines = content => content.replace(/\n/g, '')
66
- const trim = content => content.trim()
67
- const truncate = (content, attribute) => {
68
- try {
69
- const [length, omission] = attribute.split(',')
70
- return content.length > Number.parseInt(length, 10) ?
71
- content.slice(0, length) + (omission || '...') :
72
- content
73
- } catch {
74
- const length = Number.parseInt(attribute, 10)
75
- return content.length > length ? content.slice(0, length) + '...' : content
76
- }
77
- }
78
-
79
- const truncateWords = (content, attribute) => {
80
- try {
81
- const [length, omission] = attribute.split(',')
82
- return content.split(' ').slice(0, Number.parseInt(length, 10)).join(' ') + (omission || '...')
83
- } catch {
84
- const length = Number.parseInt(attribute, 10)
85
- return content.split(' ').slice(0, length).join(' ') + '...'
86
- }
87
- }
88
-
89
- // eslint-disable-next-line
90
- const urlDecode = content => content.split('+').map(decodeURIComponent).join(' ')
91
- // eslint-disable-next-line
92
- const urlEncode = content => content.split(' ').map(encodeURIComponent).join('+')
93
-
94
- exports.append = append
95
- exports.capitalize = capitalize
96
- exports.ceil = ceil
97
- exports['divide-by'] = divide
98
- exports.divide = divide
99
- exports.escape = escape
100
- exports['escape-once'] = escapeOnce
101
- exports.floor = floor
102
- exports.lowercase = lowercase
103
- exports.lstrip = lstrip
104
- exports.minus = minus
105
- exports.modulo = modulo
106
- exports.multiply = multiply
107
- exports['newline-to-br'] = newlineToBr
108
- exports.plus = plus
109
- exports.prepend = prepend
110
- exports.remove = remove
111
- exports['remove-first'] = removeFirst
112
- exports.replace = replace
113
- exports['replace-first'] = replaceFirst
114
- exports.round = round
115
- exports.rstrip = rstrip
116
- exports.uppercase = uppercase
117
- exports.size = size
118
- exports.slice = slice
119
- exports.strip = trim
120
- exports['strip-newlines'] = stripNewlines
121
- exports.times = multiply
122
- exports.trim = trim
123
- exports.truncate = truncate
124
- exports['truncate-words'] = truncateWords
125
- exports['url-decode'] = urlDecode
126
- exports['url-encode'] = urlEncode
1
+ const escapeMap = {
2
+ '&': '&amp;',
3
+ '<': '&lt;',
4
+ '>': '&gt;',
5
+ '"': '&#34;',
6
+ '\'': '&#39;'
7
+ }
8
+
9
+ const unescapeMap = {
10
+ '&amp;': '&',
11
+ '&lt;': '<',
12
+ '&gt;': '>',
13
+ '&#34;': '"',
14
+ '&#39;': '\''
15
+ }
16
+
17
+ const unescape = string => string.replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m])
18
+
19
+ const append = (content, attribute) => content + attribute
20
+ const capitalize = content => content.charAt(0).toUpperCase() + content.slice(1)
21
+ const ceil = content => Math.ceil(Number.parseFloat(content))
22
+ const divide = (content, attribute) => Number.parseFloat(content) / Number.parseFloat(attribute)
23
+ const escape = content => content.replace(/["&'<>]/g, m => escapeMap[m])
24
+ const escapeOnce = content => escape(unescape(content))
25
+ const floor = content => Math.floor(Number.parseFloat(content))
26
+ const lowercase = content => content.toLowerCase()
27
+ const lstrip = content => content.replace(/^\s+/, '')
28
+ const minus = (content, attribute) => Number.parseFloat(content) - Number.parseFloat(attribute)
29
+ const modulo = (content, attribute) => Number.parseFloat(content) % Number.parseFloat(attribute)
30
+ const multiply = (content, attribute) => Number.parseFloat(content) * Number.parseFloat(attribute)
31
+ const newlineToBr = content => content.replace(/\n/g, '<br>')
32
+ const plus = (content, attribute) => Number.parseFloat(content) + Number.parseFloat(attribute)
33
+ const prepend = (content, attribute) => attribute + content
34
+
35
+ const remove = (content, attribute) => {
36
+ const regex = new RegExp(attribute, 'g')
37
+ return content.replace(regex, '')
38
+ }
39
+
40
+ const removeFirst = (content, attribute) => content.replace(attribute, '')
41
+ const replace = (content, attribute) => {
42
+ const [search, replace] = attribute.split('|')
43
+ const regex = new RegExp(search, 'g')
44
+ return content.replace(regex, replace)
45
+ }
46
+
47
+ const replaceFirst = (content, attribute) => {
48
+ const [search, replace] = attribute.split('|')
49
+ return content.replace(search, replace)
50
+ }
51
+
52
+ const round = content => Math.round(Number.parseFloat(content))
53
+ const rstrip = content => content.replace(/\s+$/, '')
54
+ const uppercase = content => content.toUpperCase()
55
+ const size = content => content.length
56
+ const slice = (content, attribute) => {
57
+ try {
58
+ const [start, end] = attribute.split(',')
59
+ return content.slice(start, end)
60
+ } catch {
61
+ return content.slice(attribute)
62
+ }
63
+ }
64
+
65
+ const stripNewlines = content => content.replace(/\n/g, '')
66
+ const trim = content => content.trim()
67
+ const truncate = (content, attribute) => {
68
+ try {
69
+ const [length, omission] = attribute.split(',')
70
+ return content.length > Number.parseInt(length, 10) ?
71
+ content.slice(0, length) + (omission || '...') :
72
+ content
73
+ } catch {
74
+ const length = Number.parseInt(attribute, 10)
75
+ return content.length > length ? content.slice(0, length) + '...' : content
76
+ }
77
+ }
78
+
79
+ const truncateWords = (content, attribute) => {
80
+ try {
81
+ const [length, omission] = attribute.split(',')
82
+ return content.split(' ').slice(0, Number.parseInt(length, 10)).join(' ') + (omission || '...')
83
+ } catch {
84
+ const length = Number.parseInt(attribute, 10)
85
+ return content.split(' ').slice(0, length).join(' ') + '...'
86
+ }
87
+ }
88
+
89
+ // eslint-disable-next-line
90
+ const urlDecode = content => content.split('+').map(decodeURIComponent).join(' ')
91
+ // eslint-disable-next-line
92
+ const urlEncode = content => content.split(' ').map(encodeURIComponent).join('+')
93
+
94
+ exports.append = append
95
+ exports.capitalize = capitalize
96
+ exports.ceil = ceil
97
+ exports['divide-by'] = divide
98
+ exports.divide = divide
99
+ exports.escape = escape
100
+ exports['escape-once'] = escapeOnce
101
+ exports.floor = floor
102
+ exports.lowercase = lowercase
103
+ exports.lstrip = lstrip
104
+ exports.minus = minus
105
+ exports.modulo = modulo
106
+ exports.multiply = multiply
107
+ exports['newline-to-br'] = newlineToBr
108
+ exports.plus = plus
109
+ exports.prepend = prepend
110
+ exports.remove = remove
111
+ exports['remove-first'] = removeFirst
112
+ exports.replace = replace
113
+ exports['replace-first'] = replaceFirst
114
+ exports.round = round
115
+ exports.rstrip = rstrip
116
+ exports.uppercase = uppercase
117
+ exports.size = size
118
+ exports.slice = slice
119
+ exports.strip = trim
120
+ exports['strip-newlines'] = stripNewlines
121
+ exports.times = multiply
122
+ exports.trim = trim
123
+ exports.truncate = truncate
124
+ exports['truncate-words'] = truncateWords
125
+ exports['url-decode'] = urlDecode
126
+ exports['url-encode'] = urlEncode