New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

twig

Package Overview
Dependencies
Maintainers
7
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twig - npm Package Compare versions

Comparing version 1.15.4 to 1.16.0

.github/workflows/tests.yml

20

ASYNC.md

@@ -119,3 +119,3 @@ # Twig Asynchronous Rendering

The rendering mode of Twig.js internally is determined by the `allow_async` argument that can be passed into `Twig.expression.parse`, `Twig.logic.parse`, `Twig.parse` and `Twig.Template.render`. Detecting if at any point code runs asynchronously is explained in [detecting asynchronous behaviour](#detecting-asynchronous-behaviour).
The rendering mode of Twig.js internally is determined by the `allowAsync` argument that can be passed into `Twig.expression.parse`, `Twig.logic.parse`, `Twig.parse` and `Twig.Template.render`. Detecting if at any point code runs asynchronously is explained in [detecting asynchronous behaviour](#detecting-asynchronous-behaviour).

@@ -161,6 +161,6 @@ For the end user switching between synchronous and asynchronous is as simple as using a different method on the template instance.

1. Set a variable `is_async = true`
1. Set a variable `isAsync = true`
2. Run the promise chain that might contain some asynchronous behaviour.
3. As the last method in the promise chain set `is_async = false`
4. Underneath the promise chain test whether `is_async` is `true`
3. As the last method in the promise chain set `isAsync = false`
4. Underneath the promise chain test whether `isAsync` is `true`

@@ -174,3 +174,3 @@ This pattern works because the last method in the chain will be executed in the next run of the eventloop (`setTimeout`/`setImmediate`).

```javascript
var is_async = true;
var isAsync = true;

@@ -184,6 +184,6 @@ Twig.Promise.resolve()

.then(function() {
is_async = false;
isAsync = false;
});
if (is_async)
if (isAsync)
console.log('method ran asynchronous');

@@ -202,3 +202,3 @@

```javascript
var is_async = true;
var isAsync = true;

@@ -211,6 +211,6 @@ Twig.Promise.resolve()

.then(function() {
is_async = false;
isAsync = false;
});
if (is_async)
if (isAsync)
console.log('method ran asynchronous');

@@ -217,0 +217,0 @@

@@ -0,1 +1,28 @@

Version 1.16.0, release 2023-02-27
----------------------------------
Major improvements:
* Fix passing context around by @willrowe in https://github.com/twigjs/twig.js/pull/850
* Add namespace support to `source` function by @willrowe in https://github.com/twigjs/twig.js/pull/823
* Use src/twig.js as package's main script instead of the compiled twig.js by @RobLoach in https://github.com/twigjs/twig.js/pull/829
Minor improvements:
* Fix macro changing context in loop by @mihkeleidast in https://github.com/twigjs/twig.js/pull/773
* Imported function PATHS.strip_slash() missing by @murageyun in https://github.com/twigjs/twig.js/pull/770
* Convert non-string values to string before replacing by @kmonahan in https://github.com/twigjs/twig.js/pull/797
* Add GitHub actions test workflow by @willrowe in https://github.com/twigjs/twig.js/pull/817
* Fix date parsing with timezones by @plepe in https://github.com/twigjs/twig.js/pull/765
* Fixed Twig official's URL on README.md by @Geolim4 in https://github.com/twigjs/twig.js/pull/822
* Add tests for whitespace in paths by @willrowe in https://github.com/twigjs/twig.js/pull/824
* Fix multiple includes with embeds by @willrowe in https://github.com/twigjs/twig.js/pull/828
* Update to Mocha 9.x by @RobLoach in https://github.com/twigjs/twig.js/pull/831
* Add test for issue #767 by @willrowe in https://github.com/twigjs/twig.js/pull/837
* Add support for `divisible by` test by @willrowe in https://github.com/twigjs/twig.js/pull/838
* Add support for `with` tag without context or `only` keyword by @willrowe in https://github.com/twigjs/twig.js/pull/839
* Use v3 of `actions/checkout` by @willrowe in https://github.com/twigjs/twig.js/pull/846
* Test on more node versions by @willrowe in https://github.com/twigjs/twig.js/pull/847
* Fix webpack 5 compatibility by @willrowe in https://github.com/twigjs/twig.js/pull/849
* Add test to confirm `renderFile` error handling by @willrowe in https://github.com/twigjs/twig.js/pull/851
* Fix casing of variables in docs by @willrowe in https://github.com/twigjs/twig.js/pull/852
* Bumped dependencies by @dependabot
Version 1.15.4, released 2020-11-27

@@ -2,0 +29,0 @@ -----------------------------------

const FS = require('fs');
const minimatch = require('minimatch');
const WALK = require('walk');
const Twig = require('../twig');
const Twig = require('..');
const PATHS = require('./paths');

@@ -6,0 +6,0 @@

@@ -5,3 +5,3 @@ {

"description": "JS port of the Twig templating language.",
"version": "1.15.4",
"version": "1.16.0",
"homepage": "https://github.com/twigjs/twig.js",

@@ -19,5 +19,5 @@ "license": "BSD-2-Clause",

},
"main": "twig.js",
"main": "src/twig.js",
"engines": {
"node": ">=8.16"
"node": ">=10"
},

@@ -32,3 +32,3 @@ "bin": {

"test": "mocha -r should",
"build": "webpack",
"build": "node node/build.js",
"posttest": "xo src lib bin"

@@ -48,10 +48,11 @@ },

"eslint-plugin-mocha": "^6.3.0",
"mocha": "^7.0.1",
"mocha": "^9.0.0",
"path-browserify": "^1.0.1",
"should": "^13.2.3",
"should-sinon": "0.0.6",
"sinon": "^9.0.0",
"terser-webpack-plugin": "^2.3.5",
"tokenizer": "1.1.x",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11",
"terser-webpack-plugin": "^5.3.6",
"tokenizer2": "^2.0.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"xo": "^0.26.1"

@@ -58,0 +59,0 @@ },

@@ -13,3 +13,3 @@ [![Known Vulnerabilities](https://snyk.io/test/github/twigjs/twig.js/badge.svg)](https://snyk.io/test/github/twigjs/twig.js)

Twig.js is a pure JavaScript implementation of the Twig PHP templating language
(<http://twig.sensiolabs.org/>)
(<https://twig.symfony.com/>)

@@ -96,3 +96,3 @@ The goal is to provide a library that is compatible with both browsers and server side JavaScript environments such as node.js.

app.set("twig options", {
allow_async: true, // Allow asynchronous compiling
allowAsync: true, // Allow asynchronous compiling
strict_variables: false

@@ -99,0 +99,0 @@ });

@@ -1010,6 +1010,6 @@ // ## twig.core.js

*/
Twig.ParseState = function (template, blockOverrides) {
Twig.ParseState = function (template, blockOverrides, context) {
this.renderedBlocks = {};
this.overrideBlocks = blockOverrides === undefined ? {} : blockOverrides;
this.context = {};
this.context = context === undefined ? {} : context;
this.macros = {};

@@ -1329,5 +1329,5 @@ this.nestingStack = [];

return Twig.async.potentiallyAsync(template, allowAsync, () => {
const state = new Twig.ParseState(template, params.blocks);
const state = new Twig.ParseState(template, params.blocks, context);
return state.parseAsync(template.tokens, context)
return state.parseAsync(template.tokens)
.then(output => {

@@ -1334,0 +1334,0 @@ let parentTemplate;

@@ -146,3 +146,3 @@ // ## twig.expression.js

type: Twig.expression.type.test,
regex: /^is\s+(not)?\s*([a-zA-Z_]\w*(\s?as)?)/,
regex: /^is\s+(not)?\s*([a-zA-Z_]\w*(\s?(?:as|by))?)/,
next: Twig.expression.set.operations.concat([Twig.expression.type.parameter.start]),

@@ -149,0 +149,0 @@ compile(token, stack, output) {

@@ -6,3 +6,3 @@ // ## twig.factory.js

const Twig = {
VERSION: '1.14.0'
VERSION: '1.16.0'
};

@@ -9,0 +9,0 @@

@@ -259,2 +259,4 @@ // ## twig.functions.js

source(name, ignoreMissing) {
const state = this;
const {namespaces} = state.template.options;
let templateSource;

@@ -264,4 +266,8 @@ let templateFound = false;

let loader;
const path = name;
let path = name;
if (namespaces && typeof namespaces === 'object') {
path = Twig.path.expandNamespace(namespaces, path);
}
// If we are running in a node.js environment, set the loader to 'fs'.

@@ -268,0 +274,0 @@ if (isNodeEnvironment) {

@@ -47,6 +47,7 @@ // ## twig.lib.js

Twig.lib.replaceAll = function (string, search, replace) {
// Convert type to string if needed
const stringToChange = typeof string === 'string' ? string : string.toString();
// Escape possible regular expression syntax
const searchEscaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return string.replace(new RegExp(searchEscaped, 'g'), replace);
return stringToChange.replace(new RegExp(searchEscaped, 'g'), replace);
};

@@ -53,0 +54,0 @@

@@ -1009,3 +1009,4 @@ // ## twig.logic.js

const macroContext = {
...context,
// Use current state context because state context includes current loop variables as well
...state.context,
_self: state.macros

@@ -1242,3 +1243,2 @@ };

data: token.output,
id: state.template.id,
base: state.template.base,

@@ -1299,3 +1299,3 @@ path: state.template.path,

type: Twig.logic.type.with,
regex: /^(?:with\s+([\S\s]+?))(?:\s|$)(only)?$/,
regex: /^(?:with(?:\s+([\S\s]+?))?)(?:\s|$)(only)?$/,
next: [

@@ -1345,5 +1345,7 @@ Twig.logic.type.endwith

const isolatedState = new Twig.ParseState(state.template, undefined, innerContext);
return promise
.then(() => {
return state.parseAsync(token.output, innerContext);
return isolatedState.parseAsync(token.output);
})

@@ -1350,0 +1352,0 @@ .then(output => {

@@ -13,2 +13,17 @@ // ## twig.path.js

/**
* @param {Twig.Template} template
* @param {string} path
*/
Twig.path.expandNamespace = function (namespaces, path) {
const namespaceIdentifiers = Object.keys(namespaces);
const pattern = new RegExp(`^(?:@(${namespaceIdentifiers.join('|')})/|(${namespaceIdentifiers.join('|')})::)`);
return path.replace(pattern, (wholeMatch, atNamespace, colonNamespace) => {
const namespaceIdentifier = (atNamespace === undefined ? colonNamespace : atNamespace);
return `${namespaces[namespaceIdentifier]}/`;
});
};
/**
* Generate the canonical version of a url based on the given base path and file path and in

@@ -23,32 +38,13 @@ * the previously registered namespaces.

Twig.path.parsePath = function (template, _file) {
let k = null;
const {namespaces} = template.options;
let file = _file || '';
const file = _file || '';
const hasNamespaces = namespaces && typeof namespaces === 'object';
if (hasNamespaces) {
for (k in namespaces) {
if (!file.includes(k)) {
continue;
}
let path = (hasNamespaces ? Twig.path.expandNamespace(namespaces, file) : file);
// Check if keyed namespace exists at path's start
const colon = new RegExp('^' + k + '::');
const atSign = new RegExp('^@' + k + '/');
// Add slash to the end of path
const namespacePath = namespaces[k].replace(/([^/])$/, '$1/');
if (colon.test(file)) {
file = file.replace(colon, namespacePath);
return file;
}
if (atSign.test(file)) {
file = file.replace(atSign, namespacePath);
return file;
}
}
if (path === file) {
path = Twig.path.relativePath(template, file);
}
return Twig.path.relativePath(template, file);
return path;
};

@@ -55,0 +51,0 @@

@@ -37,5 +37,9 @@ // ## twig.tests.js

},
divisibleby(value, params) {
'divisible by'(value, params) {
return value % params[0] === 0;
},
divisibleby(value, params) {
console.warn('`divisibleby` is deprecated use `divisible by`');
return Twig.tests['divisible by'](value, params);
},
defined(value) {

@@ -42,0 +46,0 @@ return value !== undefined;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc