@lowdefy/nunjucks 4.0.0-alpha.26 → 4.0.0-alpha.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/nunjucks",
3
- "version": "4.0.0-alpha.26",
3
+ "version": "4.0.0-alpha.29",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -33,25 +33,28 @@
33
33
  "dist/*"
34
34
  ],
35
35
  "scripts": {
36
- "build": "yarn swc",
36
+ "build": "webpack --config webpack.config.js",
37
37
  "clean": "rm -rf dist",
38
- "prepare": "yarn build",
39
- "swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
38
+ "prepublishOnly": "pnpm build",
40
39
  "test": "jest --coverage"
41
40
  },
42
41
  "dependencies": {
43
- "@lowdefy/helpers": "4.0.0-alpha.26",
44
- "moment": "2.29.4",
45
- "nunjucks": "3.2.3"
42
+ "@lowdefy/helpers": "4.0.0-alpha.29",
43
+ "moment": "2.29.4"
46
44
  },
47
45
  "devDependencies": {
48
46
  "@swc/cli": "0.1.57",
49
47
  "@swc/core": "1.2.194",
50
48
  "@swc/jest": "0.2.21",
51
- "jest": "28.1.0"
49
+ "clean-webpack-plugin": "4.0.0",
50
+ "jest": "28.1.0",
51
+ "nunjucks": "3.2.3",
52
+ "swc-loader": "0.2.3",
53
+ "webpack": "5.74.0",
54
+ "webpack-cli": "4.10.0"
52
55
  },
53
56
  "publishConfig": {
54
57
  "access": "public"
55
58
  },
56
- "gitHead": "ef60e34f87b95204d103db4a65e4ba3c54a5a1b5"
59
+ "gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
57
60
  }
@@ -1,64 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ /** DERIVED FROM
16
- * nunjucks-date-filter-local
17
- * Fork from https://github.com/piwi/nunjucks-date-filter
18
- *
19
- * Copyright (c) 2015 Pierre Cassat
20
- * Licensed under the Apache 2.0 license.
21
- */ import moment from 'moment';
22
- import nunjucks from 'nunjucks';
23
- import { type } from '@lowdefy/helpers';
24
- // default default format (ISO 8601)
25
- let dateFilterDefaultFormat = null;
26
- // a date filter for Nunjucks
27
- // usage: {{ my_date | date(format) }}
28
- // see: <http://momentjs.com/docs/>
29
- const dateFilter = (date, format, ...args)=>{
30
- // for no date, return undefined.
31
- if (type.isNone(date)) {
32
- return '';
33
- }
34
- // allow for moment function chaining, but return "Invalid date" for objects and arrays.
35
- if ((type.isArray(date) || type.isObject(date)) && !(date instanceof moment)) {
36
- return 'Invalid date';
37
- }
38
- let result;
39
- const errs = [];
40
- let obj;
41
- try {
42
- obj = moment(date);
43
- if (obj[format] && type.isFunction(obj[format])) {
44
- result = obj[format](...args);
45
- } else {
46
- result = obj.format(format || dateFilterDefaultFormat);
47
- }
48
- } catch (err) {
49
- errs.push(err);
50
- }
51
- if (errs.length) {
52
- return errs.join('\n');
53
- }
54
- return result;
55
- };
56
- // set default format for date
57
- dateFilter.setDefaultFormat = (format)=>{
58
- dateFilterDefaultFormat = format;
59
- };
60
- // install the filter to nunjucks environment
61
- dateFilter.install = (env, customName)=>{
62
- (env || nunjucks.configure()).addFilter(customName || 'date', dateFilter);
63
- };
64
- export default dateFilter;
package/dist/index.js DELETED
@@ -1,70 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import nunjucks from 'nunjucks';
16
- import { type } from '@lowdefy/helpers';
17
- import dateFilter from './dateFilter.js';
18
- // dateFilter.setDefaultFormat('YYYY-MM-DD');
19
- export const nunjucksEnv = new nunjucks.Environment();
20
- nunjucksEnv.addFilter('date', dateFilter);
21
- const nunjucksTemplates = {};
22
- // slow
23
- export const nunjucksString = (templateString, value)=>{
24
- if (type.isPrimitive(value)) {
25
- return nunjucksEnv.renderString(templateString, {
26
- value
27
- });
28
- }
29
- return nunjucksEnv.renderString(templateString, value);
30
- };
31
- export const validNunjucksString = (templateString, returnError = false)=>{
32
- try {
33
- nunjucksString(templateString, {});
34
- return true;
35
- } catch (e) {
36
- if (returnError) {
37
- return {
38
- name: e.name,
39
- message: e.message
40
- };
41
- }
42
- return false;
43
- }
44
- };
45
- // fast
46
- // test with memoization
47
- // this method compiles a nunjucks string only if the client has not compiled the same string before.
48
- export const nunjucksFunction = (templateString)=>{
49
- // template was already compiled
50
- if (type.isFunction(nunjucksTemplates[templateString])) {
51
- return nunjucksTemplates[templateString];
52
- }
53
- if (type.isString(templateString)) {
54
- const template = nunjucks.compile(templateString, nunjucksEnv);
55
- // execute once to throw catch template errors
56
- template.render({});
57
- nunjucksTemplates[templateString] = (value)=>{
58
- if (type.isPrimitive(value)) {
59
- return template.render({
60
- value
61
- });
62
- }
63
- return template.render(value);
64
- };
65
- } else {
66
- // for non string types like booleans or objects
67
- nunjucksTemplates[templateString] = ()=>templateString;
68
- }
69
- return nunjucksTemplates[templateString];
70
- };