jlto 1.2.3 β†’ 1.4.1

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/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v16
package/README.md CHANGED
@@ -1,6 +1,15 @@
1
+ # Support Ukraine πŸ‡ΊπŸ‡¦
2
+
3
+ - Via United24 platform (the initiative of the President of Ukraine):
4
+ - [One click donation (credit card, bank transfer or crypto)](https://u24.gov.ua/)
5
+ - Via National Bank of Ukraine:
6
+ - [Ukrainian army](https://bank.gov.ua/en/about/support-the-armed-forces)
7
+ - [Humanitarian aid to Ukraine](https://bank.gov.ua/en/about/humanitarian-aid-to-ukraine)
8
+
1
9
  # JLTO
2
10
 
3
- [![Codeship](https://app.codeship.com/projects/c496b690-12e2-0137-3a15-526d29fa1101/status?branch=master)](https://app.codeship.com/projects/327499) [![Coverage](https://coveralls.io/repos/github/dmytro-krekota/jlto/badge.svg?branch=master)](https://coveralls.io/github/dmytro-krekota/jlto?branch=master) [![Dependencies](https://david-dm.org/dmytro-krekota/jlto.svg)](https://david-dm.org/dmytro-krekota/jlto) [![DevDependencies](https://david-dm.org/dmytro-krekota/jlto/dev-status.svg)](https://david-dm.org/dmytro-krekota/jlto?type=dev) [![Join the chat at https://gitter.im/dmytro-krekota_jlto/Lobby](https://badges.gitter.im/dmytro-krekota_jlto/Lobby.svg)](https://gitter.im/dmytro-krekota_jlto/community?source=orgpage)
11
+ [![CircleCI](https://circleci.com/gh/dmytro-krekota/jlto.svg?style=svg)](https://app.circleci.com/pipelines/github/dmytro-krekota/jlto)
12
+ [![Coverage](https://coveralls.io/repos/github/dmytro-krekota/jlto/badge.svg?branch=master)](https://coveralls.io/github/dmytro-krekota/jlto?branch=master) [![Join the chat at https://gitter.im/dmytro-krekota_jlto/Lobby](https://badges.gitter.im/dmytro-krekota_jlto/Lobby.svg)](https://gitter.im/dmytro-krekota_jlto/community?source=orgpage)
4
13
 
5
14
  [![NPM](https://nodei.co/npm/jlto.png?downloads=true)](https://nodei.co/npm/jlto/)
6
15
 
@@ -12,29 +21,29 @@
12
21
 
13
22
  **Supported template engines:**
14
23
 
15
- * [Nunjucks](https://mozilla.github.io/nunjucks/) (Tested with unit tests)
16
- * [Twig.js](https://github.com/twigjs/twig.js) (Tested with unit tests)
17
- * [LiquidNode](https://github.com/sirlantis/liquid-node) (Tested with unit tests)
18
- * [Twig](https://twig.sensiolabs.org/)
19
- * [Jinja](http://jinja.pocoo.org/)
20
- * [Django](https://docs.djangoproject.com/en/1.11/ref/templates/language/)
21
- * [Liquid](https://shopify.github.io/liquid/)
22
- * [Jinjava](https://github.com/HubSpot/jinjava)
24
+ - [Nunjucks](https://mozilla.github.io/nunjucks/) (Tested with unit tests)
25
+ - [Twig.js](https://github.com/twigjs/twig.js) (Tested with unit tests)
26
+ - [LiquidNode](https://github.com/sirlantis/liquid-node) (Tested with unit tests)
27
+ - [Twig](https://twig.sensiolabs.org/)
28
+ - [Jinja](http://jinja.pocoo.org/)
29
+ - [Django](https://docs.djangoproject.com/en/1.11/ref/templates/language/)
30
+ - [Liquid](https://shopify.github.io/liquid/)
31
+ - [Jinjava](https://github.com/HubSpot/jinjava)
23
32
 
24
33
  **Available options:**
25
34
 
26
- * expressionStart - symbols at the beginning of expressions
27
- * expressionEnd - symbols at the end of expressions
28
- * blockStart - symbols at the beginning of blocks
29
- * blockEnd - symbols at the end of blocks
30
- * commentStart - symbols at the beginning of comments
31
- * commentEnd - symbols at the beginning of comments
32
- * specialChars - special chars in blocks and expressions
33
- * cleanupBlocks - flag for optimize blocks
34
- * cleanupExpressions - flag for optimize expressions
35
- * removeComments - flag for removing comments
36
- * minifyHtml - flag for minifying html code with [html-minifier](https://www.npmjs.com/package/html-minifier)
37
- * minifyHtmlOptions - options for html-minifier
35
+ - expressionStart - symbols at the beginning of expressions
36
+ - expressionEnd - symbols at the end of expressions
37
+ - blockStart - symbols at the beginning of blocks
38
+ - blockEnd - symbols at the end of blocks
39
+ - commentStart - symbols at the beginning of comments
40
+ - commentEnd - symbols at the beginning of comments
41
+ - specialChars - special chars in blocks and expressions
42
+ - cleanupBlocks - flag for optimize blocks
43
+ - cleanupExpressions - flag for optimize expressions
44
+ - removeComments - flag for removing comments
45
+ - minifyHtml - flag for minifying html code with [html-minifier](https://www.npmjs.com/package/html-minifier)
46
+ - minifyHtmlOptions - options for html-minifier
38
47
 
39
48
  See default values for above options [here](https://github.com/dmytro-krekota/jlto/blob/master/lib/core/default.js).
40
49
 
@@ -43,7 +52,7 @@ See default values for above options [here](https://github.com/dmytro-krekota/jl
43
52
  **Simple example:**
44
53
 
45
54
  ```js
46
- let jlto = require("jlto");
55
+ let jlto = require('jlto');
47
56
  let template = `
48
57
  {{ hello }}
49
58
  {{ "<John & Paul> ?" | escape }}
@@ -61,7 +70,7 @@ let optimizedTemplate = jlto.optimizeString(template);
61
70
  **Example of using minifyHtml option:**
62
71
 
63
72
  ```js
64
- let jlto = require("jlto");
73
+ let jlto = require('jlto');
65
74
  let template = `
66
75
  <div {% if id %}id="{{ id | escape('html_attr') }}"{% endif %} class="section-container {{ classes | join(' ') | html_attribute }}">
67
76
  <div class="section-writables">
@@ -91,8 +100,7 @@ module.exports = (grunt) => {
91
100
  try {
92
101
  fileContent = jlto.optimizeString(fileContent, {minifyHtml: true});
93
102
  fs.writeFileSync(filePath, fileContent);
94
- } catch (ignored) {
95
- }
103
+ } catch (ignored) {}
96
104
  });
97
105
  return done();
98
106
  });
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- let jlto = require('./lib/jlto')
2
-
3
- module.exports = new jlto()
1
+ let jlto = require('./lib/jlto');
2
+
3
+ module.exports = new jlto();
@@ -20,10 +20,10 @@ class Default {
20
20
  collapseWhitespace: true,
21
21
  minifyJS: true,
22
22
  minifyCSS: true,
23
- ignoreCustomFragments: [/\{([{%])[^}]+[%}]\}/]
24
- }
25
- }
23
+ ignoreCustomFragments: [/\{([{%])[^}]+[%}]\}/],
24
+ },
25
+ };
26
26
  }
27
27
  }
28
28
 
29
- module.exports = Default
29
+ module.exports = Default;
package/lib/core/utils.js CHANGED
@@ -3,12 +3,12 @@
3
3
  */
4
4
  class Utils {
5
5
  static isNull(value) {
6
- return value === null
6
+ return value === null;
7
7
  }
8
8
 
9
9
  static isUndefined(value) {
10
- return value === undefined
10
+ return value === undefined;
11
11
  }
12
12
  }
13
13
 
14
- module.exports = Utils
14
+ module.exports = Utils;
@@ -3,72 +3,72 @@
3
3
  */
4
4
  class BlocksHelper {
5
5
  constructor(options) {
6
- this.options = options
7
- this.utils = require('./../core/utils')
6
+ this.options = options;
7
+ this.utils = require('./../core/utils');
8
8
  }
9
9
 
10
10
  getBlockWithoutExtraSpaces(expression) {
11
- let body = expression.slice(this.options.blockStart.length).slice(0, -this.options.blockEnd.length)
12
- let resultBody = ''
13
- let i
14
- let waitForChar
11
+ let body = expression.slice(this.options.blockStart.length).slice(0, -this.options.blockEnd.length);
12
+ let resultBody = '';
13
+ let i;
14
+ let waitForChar;
15
15
 
16
- body = body.trim()
16
+ body = body.trim();
17
17
  for (i = 0; i < body.length; i++) {
18
18
  if (waitForChar && body[i] !== waitForChar) {
19
- resultBody += body[i]
20
- continue
19
+ resultBody += body[i];
20
+ continue;
21
21
  }
22
- if (body[i] === '"' || body[i] === '\'') {
22
+ if (body[i] === '"' || body[i] === "'") {
23
23
  if (!waitForChar) {
24
- waitForChar = body[i]
24
+ waitForChar = body[i];
25
25
  } else {
26
- waitForChar = null
26
+ waitForChar = null;
27
27
  }
28
28
  }
29
29
  if (this.options.specialChars.indexOf(body[i]) >= 0) {
30
- resultBody = resultBody.trim()
30
+ resultBody = resultBody.trim();
31
31
  }
32
32
  if (this.options.specialChars.indexOf(resultBody[resultBody.length - 1]) >= 0 && body[i] === ' ') {
33
- continue
33
+ continue;
34
34
  }
35
35
  if (resultBody[resultBody.length - 1] === ' ' && body[i] === ' ') {
36
- continue
36
+ continue;
37
37
  }
38
38
  if (body[i] !== '\n') {
39
- resultBody += body[i]
39
+ resultBody += body[i];
40
40
  }
41
41
  }
42
42
 
43
- return this.options.blockStart + resultBody + this.options.blockEnd
43
+ return this.options.blockStart + resultBody + this.options.blockEnd;
44
44
  }
45
45
 
46
46
  clearExtraSpaces(template) {
47
- let i
48
- let startIndex = null
49
- let tempSubstring
50
- let resultString = ''
47
+ let i;
48
+ let startIndex = null;
49
+ let tempSubstring;
50
+ let resultString = '';
51
51
 
52
52
  for (i = 0; i < template.length + 1; i++) {
53
53
  if (!this.utils.isNull(startIndex)) {
54
- tempSubstring = template.substring(i - this.options.blockEnd.length, i)
54
+ tempSubstring = template.substring(i - this.options.blockEnd.length, i);
55
55
  if (tempSubstring === this.options.blockEnd) {
56
- resultString += this.getBlockWithoutExtraSpaces(template.substring(startIndex, i))
57
- startIndex = null
56
+ resultString += this.getBlockWithoutExtraSpaces(template.substring(startIndex, i));
57
+ startIndex = null;
58
58
  }
59
59
  }
60
60
  if (this.utils.isNull(startIndex)) {
61
- tempSubstring = template.substring(i, i + this.options.blockStart.length)
61
+ tempSubstring = template.substring(i, i + this.options.blockStart.length);
62
62
  if (tempSubstring === this.options.blockStart) {
63
- startIndex = i
63
+ startIndex = i;
64
64
  } else if (!this.utils.isUndefined(template[i])) {
65
- resultString += template[i]
65
+ resultString += template[i];
66
66
  }
67
67
  }
68
68
  }
69
69
 
70
- return resultString
70
+ return resultString;
71
71
  }
72
72
  }
73
73
 
74
- module.exports = BlocksHelper
74
+ module.exports = BlocksHelper;
@@ -3,35 +3,35 @@
3
3
  */
4
4
  class CommentsHelper {
5
5
  constructor(options) {
6
- this.options = options
7
- this.utils = require('./../core/utils')
6
+ this.options = options;
7
+ this.utils = require('./../core/utils');
8
8
  }
9
9
 
10
10
  removeComments(template) {
11
- let i
12
- let startIndex = null
13
- let tempString
14
- let resultString = ''
11
+ let i;
12
+ let startIndex = null;
13
+ let tempString;
14
+ let resultString = '';
15
15
 
16
16
  for (i = 0; i < template.length + 1; i++) {
17
17
  if (!this.utils.isNull(startIndex)) {
18
- tempString = template.substring(i - this.options.commentEnd.length, i)
18
+ tempString = template.substring(i - this.options.commentEnd.length, i);
19
19
  if (tempString === this.options.commentEnd) {
20
- startIndex = null
20
+ startIndex = null;
21
21
  }
22
22
  }
23
23
  if (this.utils.isNull(startIndex)) {
24
- tempString = template.substring(i, i + this.options.commentStart.length)
24
+ tempString = template.substring(i, i + this.options.commentStart.length);
25
25
  if (tempString === this.options.commentStart) {
26
- startIndex = i
26
+ startIndex = i;
27
27
  } else if (!this.utils.isUndefined(template[i])) {
28
- resultString += template[i]
28
+ resultString += template[i];
29
29
  }
30
30
  }
31
31
  }
32
32
 
33
- return resultString
33
+ return resultString;
34
34
  }
35
35
  }
36
36
 
37
- module.exports = CommentsHelper
37
+ module.exports = CommentsHelper;
@@ -3,72 +3,72 @@
3
3
  */
4
4
  class ExpressionsHelper {
5
5
  constructor(options) {
6
- this.options = options
7
- this.utils = require('./../core/utils')
6
+ this.options = options;
7
+ this.utils = require('./../core/utils');
8
8
  }
9
9
 
10
10
  getExpressionWithoutExtraSpaces(expression) {
11
- let body = expression.slice(this.options.expressionStart.length).slice(0, -this.options.expressionEnd.length)
12
- let resultBody = ''
13
- let i
14
- let waitForChar
11
+ let body = expression.slice(this.options.expressionStart.length).slice(0, -this.options.expressionEnd.length);
12
+ let resultBody = '';
13
+ let i;
14
+ let waitForChar;
15
15
 
16
- body = body.trim()
16
+ body = body.trim();
17
17
  for (i = 0; i < body.length; i++) {
18
18
  if (waitForChar && body[i] !== waitForChar) {
19
- resultBody += body[i]
20
- continue
19
+ resultBody += body[i];
20
+ continue;
21
21
  }
22
- if (body[i] === '"' || body[i] === '\'') {
22
+ if (body[i] === '"' || body[i] === "'") {
23
23
  if (!waitForChar) {
24
- waitForChar = body[i]
24
+ waitForChar = body[i];
25
25
  } else {
26
- waitForChar = null
26
+ waitForChar = null;
27
27
  }
28
28
  }
29
29
  if (this.options.specialChars.indexOf(body[i]) >= 0) {
30
- resultBody = resultBody.trim()
30
+ resultBody = resultBody.trim();
31
31
  }
32
32
  if (this.options.specialChars.indexOf(resultBody[resultBody.length - 1]) >= 0 && body[i] === ' ') {
33
- continue
33
+ continue;
34
34
  }
35
35
  if (resultBody[resultBody.length - 1] === ' ' && body[i] === ' ') {
36
- continue
36
+ continue;
37
37
  }
38
38
  if (body[i] !== '\n') {
39
- resultBody += body[i]
39
+ resultBody += body[i];
40
40
  }
41
41
  }
42
42
 
43
- return this.options.expressionStart + resultBody + this.options.expressionEnd
43
+ return this.options.expressionStart + resultBody + this.options.expressionEnd;
44
44
  }
45
45
 
46
46
  clearExtraSpaces(template) {
47
- let i
48
- let startIndex = null
49
- let tempSubstring
50
- let resultString = ''
47
+ let i;
48
+ let startIndex = null;
49
+ let tempSubstring;
50
+ let resultString = '';
51
51
 
52
52
  for (i = 0; i < template.length + 1; i++) {
53
53
  if (!this.utils.isNull(startIndex)) {
54
- tempSubstring = template.substring(i - this.options.expressionEnd.length, i)
54
+ tempSubstring = template.substring(i - this.options.expressionEnd.length, i);
55
55
  if (tempSubstring === this.options.expressionEnd) {
56
- resultString += this.getExpressionWithoutExtraSpaces(template.substring(startIndex, i))
57
- startIndex = null
56
+ resultString += this.getExpressionWithoutExtraSpaces(template.substring(startIndex, i));
57
+ startIndex = null;
58
58
  }
59
59
  }
60
60
  if (this.utils.isNull(startIndex)) {
61
- tempSubstring = template.substring(i, i + this.options.expressionStart.length)
61
+ tempSubstring = template.substring(i, i + this.options.expressionStart.length);
62
62
  if (tempSubstring === this.options.expressionStart) {
63
- startIndex = i
63
+ startIndex = i;
64
64
  } else if (!this.utils.isUndefined(template[i])) {
65
- resultString += template[i]
65
+ resultString += template[i];
66
66
  }
67
67
  }
68
68
  }
69
69
 
70
- return resultString
70
+ return resultString;
71
71
  }
72
72
  }
73
73
 
74
- module.exports = ExpressionsHelper
74
+ module.exports = ExpressionsHelper;
package/lib/jlto.js CHANGED
@@ -4,38 +4,38 @@
4
4
  */
5
5
  class JLTO {
6
6
  constructor() {
7
- this.defaultOptions = new (require('./core/default'))().options
7
+ this.defaultOptions = new (require('./core/default'))().options;
8
8
  }
9
9
 
10
10
  optimizeString(string, options = {}) {
11
- let expressionsHelper
12
- let blocksHelper
13
- let commentsHelper
14
- this.options = {...this.defaultOptions, ...options}
15
- expressionsHelper = new (require('./helpers/expressionsHelper'))(this.options)
16
- blocksHelper = new (require('./helpers/blocksHelper'))(this.options)
17
- commentsHelper = new (require('./helpers/commentsHelper'))(this.options)
11
+ let expressionsHelper;
12
+ let blocksHelper;
13
+ let commentsHelper;
14
+ this.options = {...this.defaultOptions, ...options};
15
+ expressionsHelper = new (require('./helpers/expressionsHelper'))(this.options);
16
+ blocksHelper = new (require('./helpers/blocksHelper'))(this.options);
17
+ commentsHelper = new (require('./helpers/commentsHelper'))(this.options);
18
18
 
19
19
  if (this.options.removeComments) {
20
- string = commentsHelper.removeComments(string)
20
+ string = commentsHelper.removeComments(string);
21
21
  }
22
22
  if (this.options.cleanupExpressions) {
23
- string = expressionsHelper.clearExtraSpaces(string)
23
+ string = expressionsHelper.clearExtraSpaces(string);
24
24
  }
25
25
  if (this.options.cleanupBlocks) {
26
- string = blocksHelper.clearExtraSpaces(string)
26
+ string = blocksHelper.clearExtraSpaces(string);
27
27
  }
28
28
  if (this.options.minifyHtml) {
29
- let minify = require('html-minifier').minify
29
+ let minify = require('html-minifier').minify;
30
30
  this.options.minifyHtmlOptions = {
31
31
  ...this.defaultOptions.minifyHtmlOptions,
32
- ...(options.minifyHtmlOptions || {})
33
- }
34
- string = minify(string, this.options.minifyHtmlOptions)
32
+ ...(options.minifyHtmlOptions || {}),
33
+ };
34
+ string = minify(string, this.options.minifyHtmlOptions);
35
35
  }
36
36
 
37
- return string
37
+ return string;
38
38
  }
39
39
  }
40
40
 
41
- module.exports = JLTO
41
+ module.exports = JLTO;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jlto",
3
- "version": "1.2.3",
3
+ "version": "1.4.1",
4
4
  "description": "Nodejs-based tool for optimizing Jinja like templates",
5
5
  "keywords": [
6
6
  "jinja",
@@ -34,11 +34,11 @@
34
34
  "scripts": {
35
35
  "lint": "eslint test lib --max-warnings=0 --fix",
36
36
  "test": "npm run lint && jest --coverage",
37
- "codeship-testing": "jest --coverage && cat ./coverage/lcov.info | coveralls",
37
+ "ci-testing": "jest --coverage && cat ./coverage/lcov.info | coveralls",
38
38
  "prettier": "prettier \"{test,lib}/**/*.js\" --write"
39
39
  },
40
40
  "engines": {
41
- "node": ">=12"
41
+ "node": ">=16"
42
42
  },
43
43
  "pre-commit": [
44
44
  "prettier",
@@ -54,15 +54,17 @@
54
54
  ]
55
55
  },
56
56
  "devDependencies": {
57
- "chai": "4.2.0",
58
- "coveralls": "3.0.7",
59
- "eslint": "6.6.0",
60
- "jest": "24.9.0",
61
- "liquid-node": "3.0.1",
62
- "nunjucks": "3.2.0",
57
+ "chai": "4.3.6",
58
+ "coveralls": "3.1.1",
59
+ "eslint": "8.21.0",
60
+ "eslint-config-prettier": "^8.5.0",
61
+ "eslint-plugin-prettier": "^4.2.1",
62
+ "jest": "28.1.3",
63
+ "liquid": "5.1.1",
64
+ "nunjucks": "3.2.3",
63
65
  "pre-commit": "1.2.2",
64
- "prettier": "1.19.1",
65
- "twig": "1.14.0"
66
+ "prettier": "2.7.1",
67
+ "twig": "1.15.4"
66
68
  },
67
69
  "dependencies": {
68
70
  "html-minifier": "4.0.0"
package/test.dockerfile DELETED
@@ -1,9 +0,0 @@
1
- FROM node:12.13.0
2
-
3
- # Move project to /jlto directory
4
- RUN mkdir -p /jlto
5
- COPY . /jlto
6
- WORKDIR /jlto
7
-
8
- # Install dependencies
9
- RUN npm ci