A simple, expressive, extensible Liquid template engine for JavaScript — Shopify, Jekyll and GitHub Pages compatible, for Node.js, browsers, and the CLI, with TypeScript support.
+
-
-
-
-
A simple, expressive and safe Shopify / GitHub Pages compatible template engine in pure JavaScript.
-The purpose of this repo is to provide a standard Liquid implementation for the JavaScript community so that Jekyll sites, GitHub Pages and Shopify templates can be ported to Node.js without pain.
Directus: an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database.
-
Rock: An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
-
Mitosis: Write components once, run everywhere. Compiles to React, Vue, Qwik, Solid, Angular, Svelte, and more.
-
Pattern Lab: a frontend workshop environment that helps you build, view, test, and showcase your design system's UI components.
-
Builder.io: the first and only headless CMS with a visual editor that lets you drag and drop with your components, directly within your current site or app. Completely API-driven, for cleaner code and simpler workflows.
-
Microsoft Power Pages: a secure, enterprise-grade, low-code software as a service (SaaS) platform for creating, hosting, and administering modern external-facing business websites.
WISMOlabs: Post Purchase Experience platform for eCommerce retailers enhancing customer satisfaction by using LiquidJS to provide customizable post-purchase experiences through programmable email, SMS, order tracking pages, and webhooks.
-
Freshet: JSON in, page out — a Chrome extension that uses LiquidJS templates per URL pattern, so the JSON becomes a rendered, useful page.
-
-
Feel free to create a PR or contact me to add your use case into this list!
+
See the setup guide for partials, layouts, caching, and other options.
+
Used by
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Products and projects running on LiquidJS. Open a PR to add yours.
Financial Support
If you personally love LiquidJS or it's benefiting your business, please consider financially support us via GitHub Sponsors. Special thanks to our sponsors!
diff --git a/api/interfaces/_internal_.Buffer.html b/api/interfaces/_internal_.Buffer.html
index 68f215cec..693c96b82 100644
--- a/api/interfaces/_internal_.Buffer.html
+++ b/api/interfaces/_internal_.Buffer.html
@@ -117,11 +117,11 @@ Comparison is based on the actual sequence of bytes in each Buffer.
1 is returned if target should come beforebuf when sorted.
-1 is returned if target should come afterbuf when sorted.
The optional targetStart, targetEnd, sourceStart, and sourceEnd arguments can be used to limit the comparison to specific ranges within target and buf respectively.
ERR_OUT_OF_RANGE is thrown if targetStart < 0, sourceStart < 0, targetEnd > target.byteLength, or sourceEnd > source.byteLength.
@@ -135,10 +135,10 @@ Comparison is based on the actual sequence of bytes in each Buffer.
TypedArray.prototype.set() performs the same operation, and is available
for all TypedArrays, including Node.js Buffers, although it takes
different function arguments.
for (leti = 0; i < 26; i++) { // 97 is the decimal ASCII value for 'a'. buf1[i] = i + 97; }
// Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`. buf1.copy(buf2, 8, 16, 20); // This is equivalent to: // buf2.set(buf1.subarray(16, 20), 8);
for (leti = 0; i < 26; i++) { // 97 is the decimal ASCII value for 'a'. buf1[i] = i + 97; }
// Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`. buf1.copy(buf2, 8, 16, 20); // This is equivalent to: // buf2.set(buf1.subarray(16, 20), 8);
value is coerced to a uint32 value if it is not a string, Buffer, or
@@ -177,12 +177,12 @@ integer. If the resulting integer is greater than 255 (decimal), value & 255
.
If the final write of a fill() operation falls on a multi-byte character,
then only the bytes of that character that fit into buf are written:
-
import { Buffer } from'node:buffer';
// Fill a `Buffer` with character that takes up two bytes in UTF-8.
If value contains invalid characters, it is truncated; if no valid
fill data remains, an exception is thrown:
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(5);
console.log(buf.fill('a')); // Prints: <Buffer 61 61 61 61 61> console.log(buf.fill('aazz', 'hex')); // Prints: <Buffer aa aa aa aa aa> console.log(buf.fill('zz', 'hex')); // Throws an exception.
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(5);
console.log(buf.fill('a')); // Prints: <Buffer 61 61 61 61 61> console.log(buf.fill('aazz', 'hex')); // Prints: <Buffer aa aa aa aa aa> console.log(buf.fill('zz', 'hex')); // Throws an exception.
Parameters
value: string | number | Uint8Array
The value with which to fill buf. Empty value (string, Uint8Array, Buffer) is coerced to 0.
@@ -216,7 +216,7 @@ callbackfn function one time for each element in the array.
(value, index, array): void
Parameters
value: number
index: number
array: Uint8Array
Returns void
OptionalthisArg: any
An object to which the this keyword can refer in the callbackfn function.
If thisArg is omitted, undefined is used as the this value.
If value is not a string, number, or Buffer, this method will throw a TypeError. If value is a number, it will be coerced to a valid byte value,
@@ -240,7 +240,7 @@ an integer between 0 and 255.
If byteOffset is not a number, it will be coerced to a number. If the result
of coercion is NaN or 0, then the entire buffer will be searched. This
behavior matches String.prototype.indexOf().
-
import { Buffer } from'node:buffer';
constb = Buffer.from('abcdef');
// Passing a value that's a number, but not a valid byte. // Prints: 2, equivalent to searching for 99 or 'c'. console.log(b.indexOf(99.9)); console.log(b.indexOf(256 + 99));
// Passing a byteOffset that coerces to NaN or 0. // Prints: 1, searching the whole buffer. console.log(b.indexOf('b', undefined)); console.log(b.indexOf('b', {})); console.log(b.indexOf('b', null)); console.log(b.indexOf('b', []));
+
import { Buffer } from'node:buffer';
constb = Buffer.from('abcdef');
// Passing a value that's a number, but not a valid byte. // Prints: 2, equivalent to searching for 99 or 'c'. console.log(b.indexOf(99.9)); console.log(b.indexOf(256 + 99));
// Passing a byteOffset that coerces to NaN or 0. // Prints: 1, searching the whole buffer. console.log(b.indexOf('b', undefined)); console.log(b.indexOf('b', {})); console.log(b.indexOf('b', null)); console.log(b.indexOf('b', []));
If value is an empty string or empty Buffer and byteOffset is less
@@ -256,7 +256,7 @@ resulting String. If omitted, the array elements are separated with a comma.
If value is not a string, number, or Buffer, this method will throw a TypeError. If value is a number, it will be coerced to a valid byte value,
@@ -264,7 +264,7 @@ an integer between 0 and 255.
If byteOffset is not a number, it will be coerced to a number. Any arguments
that coerce to NaN, like {} or undefined, will search the whole buffer.
This behavior matches String.prototype.lastIndexOf().
-
import { Buffer } from'node:buffer';
constb = Buffer.from('abcdef');
// Passing a value that's a number, but not a valid byte. // Prints: 2, equivalent to searching for 99 or 'c'. console.log(b.lastIndexOf(99.9)); console.log(b.lastIndexOf(256 + 99));
// Passing a byteOffset that coerces to NaN. // Prints: 1, searching the whole buffer. console.log(b.lastIndexOf('b', undefined)); console.log(b.lastIndexOf('b', {}));
// Passing a byteOffset that coerces to 0. // Prints: -1, equivalent to passing 0. console.log(b.lastIndexOf('b', null)); console.log(b.lastIndexOf('b', []));
+
import { Buffer } from'node:buffer';
constb = Buffer.from('abcdef');
// Passing a value that's a number, but not a valid byte. // Prints: 2, equivalent to searching for 99 or 'c'. console.log(b.lastIndexOf(99.9)); console.log(b.lastIndexOf(256 + 99));
// Passing a byteOffset that coerces to NaN. // Prints: 1, searching the whole buffer. console.log(b.lastIndexOf('b', undefined)); console.log(b.lastIndexOf('b', {}));
// Passing a byteOffset that coerces to 0. // Prints: -1, equivalent to passing 0. console.log(b.lastIndexOf('b', null)); console.log(b.lastIndexOf('b', []));
If value is an empty string or empty Buffer, byteOffset will be returned.
@@ -291,14 +291,14 @@ values.
Returns bigint
Since
v12.0.0, v10.20.0
readBigUInt64BE
readBigUInt64BE(offset?): bigint
Reads an unsigned, big-endian 64-bit integer from buf at the specifiedoffset.
This function is also available under the readBigUint64BE alias.
Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1.
Returns number
Since
v0.5.0
readIntBE
readIntBE(offset, byteLength): number
Reads byteLength number of bytes from buf at the specified offset and interprets the result as a big-endian, two's complement signed value
supporting up to 48 bits of accuracy.
Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
@@ -376,7 +376,7 @@ supporting up to 48 bits of accuracy.
Returns number
Since
v0.11.15
readIntLE
readIntLE(offset, byteLength): number
Reads byteLength number of bytes from buf at the specified offset and interprets the result as a little-endian, two's complement signed value
supporting up to 48 bits of accuracy.
Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1.
@@ -420,7 +420,7 @@ supporting up to 48 bits of accuracy.
readUIntBE
readUIntBE(offset, byteLength): number
Reads byteLength number of bytes from buf at the specified offset and interprets the result as an unsigned big-endian integer supporting
up to 48 bits of accuracy.
This function is also available under the readUintBE alias.
Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
@@ -429,7 +429,7 @@ up to 48 bits of accuracy.
readUIntLE
readUIntLE(offset, byteLength): number
Reads byteLength number of bytes from buf at the specified offset and interprets the result as an unsigned, little-endian integer supporting
up to 48 bits of accuracy.
This function is also available under the readUintLE alias.
Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.
@@ -483,7 +483,7 @@ instead of an array value.
offset and cropped by the start and end indices.
This method is not compatible with the Uint8Array.prototype.slice(),
which is a superclass of Buffer. To copy the slice, useUint8Array.prototype.slice().
// With buf.slice(), the original buffer is modified. constnotReallyCopiedBuf = buf.slice(); notReallyCopiedBuf[0]++; console.log(notReallyCopiedBuf.toString()); // Prints: cuffer console.log(buf.toString()); // Also prints: cuffer (!)
+
// With buf.slice(), the original buffer is modified. constnotReallyCopiedBuf = buf.slice(); notReallyCopiedBuf[0]++; console.log(notReallyCopiedBuf.toString()); // Prints: cuffer console.log(buf.toString()); // Also prints: cuffer (!)
Parameters
Optionalstart: number
Where the new Buffer will start.
@@ -500,7 +500,7 @@ If thisArg is omitted, undefined is used as the this value.
Function used to determine the order of the elements. It is expected to return
a negative value if first argument is less than second argument, zero if they're equal and a positive
value otherwise. If omitted, the elements are sorted in ascending order.
Interprets buf as an array of unsigned 16-bit integers and swaps the
byte order in-place. Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 2.
Interprets buf as an array of unsigned 32-bit integers and swaps the
byte order in-place. Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 4.
@@ -560,7 +560,7 @@ In particular, Buffer.from(buf.toJSON()) works like Buffer.fr
then each invalid byte is replaced with the replacement character U+FFFD.
The maximum length of a string instance (in UTF-16 code units) is available
as constants.MAX_STRING_LENGTH.
-
import { Buffer } from'node:buffer';
constbuf1 = Buffer.allocUnsafe(26);
for (leti = 0; i < 26; i++) { // 97 is the decimal ASCII value for 'a'. buf1[i] = i + 97; }
Writes string to buf at offset according to the character encoding inencoding. The length parameter is the number of bytes to write. If buf did
not contain enough space to fit the entire string, only part of string will be
written. However, partially encoded characters will not be written.
@@ -599,7 +599,7 @@ written. However, partially encoded characters will not be written.
Since
v12.0.0, v10.20.0
writeBigUInt64BE
writeBigUInt64BE(value, offset?): number
Writes value to buf at the specified offset as big-endian.
This function is also available under the writeBigUint64BE alias.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
console.log(buf); // Prints: <Buffer de ca fa fe ca ce fa de>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
console.log(buf); // Prints: <Buffer de ca fa fe ca ce fa de>
Parameters
value: bigint
Number to be written to buf.
@@ -607,7 +607,7 @@ written. However, partially encoded characters will not be written.
Returns number
offset plus the number of bytes written.
Since
v12.0.0, v10.20.0
writeBigUInt64LE
writeBigUInt64LE(value, offset?): number
Writes value to buf at the specified offset as little-endian
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
console.log(buf); // Prints: <Buffer de fa ce ca fe fa ca de>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
console.log(buf); // Prints: <Buffer de fa ce ca fe fa ca de>
This function is also available under the writeBigUint64LE alias.
@@ -621,7 +621,7 @@ written. However, partially encoded characters will not be written.
Since
v14.10.0, v12.19.0
writeDoubleBE
writeDoubleBE(value, offset?): number
Writes value to buf at the specified offset as big-endian. The value must be a JavaScript number. Behavior is undefined when value is anything
other than a JavaScript number.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeDoubleBE(123.456, 0);
console.log(buf); // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeDoubleBE(123.456, 0);
console.log(buf); // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
Parameters
value: number
Number to be written to buf.
@@ -630,7 +630,7 @@ other than a JavaScript number.
Since
v0.11.15
writeDoubleLE
writeDoubleLE(value, offset?): number
Writes value to buf at the specified offset as little-endian. The value must be a JavaScript number. Behavior is undefined when value is anything
other than a JavaScript number.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeDoubleLE(123.456, 0);
console.log(buf); // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(8);
buf.writeDoubleLE(123.456, 0);
console.log(buf); // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
Parameters
value: number
Number to be written to buf.
@@ -639,7 +639,7 @@ other than a JavaScript number.
Since
v0.11.15
writeFloatBE
writeFloatBE(value, offset?): number
Writes value to buf at the specified offset as big-endian. Behavior is
undefined when value is anything other than a JavaScript number.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeFloatBE(0xcafebabe, 0);
console.log(buf); // Prints: <Buffer 4f 4a fe bb>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeFloatBE(0xcafebabe, 0);
console.log(buf); // Prints: <Buffer 4f 4a fe bb>
Parameters
value: number
Number to be written to buf.
@@ -648,7 +648,7 @@ undefined when value is anything other than a JavaScript number.
Since
v0.11.15
writeFloatLE
writeFloatLE(value, offset?): number
Writes value to buf at the specified offset as little-endian. Behavior is
undefined when value is anything other than a JavaScript number.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeFloatLE(0xcafebabe, 0);
console.log(buf); // Prints: <Buffer bb fe 4a 4f>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeFloatLE(0xcafebabe, 0);
console.log(buf); // Prints: <Buffer bb fe 4a 4f>
Parameters
value: number
Number to be written to buf.
@@ -658,7 +658,7 @@ undefined when value is anything other than a JavaScript number.
writeInt16BE
writeInt16BE(value, offset?): number
Writes value to buf at the specified offset as big-endian. The value must be a valid signed 16-bit integer. Behavior is undefined when value is
anything other than a signed 16-bit integer.
The value is interpreted and written as a two's complement signed integer.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(2);
buf.writeInt16BE(0x0102, 0);
console.log(buf); // Prints: <Buffer 01 02>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(2);
buf.writeInt16BE(0x0102, 0);
console.log(buf); // Prints: <Buffer 01 02>
Parameters
value: number
Number to be written to buf.
@@ -668,7 +668,7 @@ anything other than a signed 16-bit integer.
writeInt16LE
writeInt16LE(value, offset?): number
Writes value to buf at the specified offset as little-endian. The value must be a valid signed 16-bit integer. Behavior is undefined when value is
anything other than a signed 16-bit integer.
The value is interpreted and written as a two's complement signed integer.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(2);
buf.writeInt16LE(0x0304, 0);
console.log(buf); // Prints: <Buffer 04 03>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(2);
buf.writeInt16LE(0x0304, 0);
console.log(buf); // Prints: <Buffer 04 03>
Parameters
value: number
Number to be written to buf.
@@ -678,7 +678,7 @@ anything other than a signed 16-bit integer.
writeInt32BE
writeInt32BE(value, offset?): number
Writes value to buf at the specified offset as big-endian. The value must be a valid signed 32-bit integer. Behavior is undefined when value is
anything other than a signed 32-bit integer.
The value is interpreted and written as a two's complement signed integer.
@@ -688,7 +688,7 @@ anything other than a signed 32-bit integer.
writeInt32LE
writeInt32LE(value, offset?): number
Writes value to buf at the specified offset as little-endian. The value must be a valid signed 32-bit integer. Behavior is undefined when value is
anything other than a signed 32-bit integer.
The value is interpreted and written as a two's complement signed integer.
@@ -699,7 +699,7 @@ anything other than a signed 32-bit integer.
signed 8-bit integer. Behavior is undefined when value is anything other than
a signed 8-bit integer.
value is interpreted and written as a two's complement signed integer.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(2);
buf.writeInt8(2, 0); buf.writeInt8(-2, 1);
console.log(buf); // Prints: <Buffer 02 fe>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(2);
buf.writeInt8(2, 0); buf.writeInt8(-2, 1);
console.log(buf); // Prints: <Buffer 02 fe>
Parameters
value: number
Number to be written to buf.
@@ -708,7 +708,7 @@ a signed 8-bit integer.
Since
v0.5.0
writeIntBE
writeIntBE(value, offset, byteLength): number
Writes byteLength bytes of value to buf at the specified offsetas big-endian. Supports up to 48 bits of accuracy. Behavior is undefined whenvalue is anything other than a
signed integer.
Writes byteLength bytes of value to buf at the specified offsetas little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
when value is anything other than a signed integer.
console.log(buf); // Prints: <Buffer ab 90 78 56 34 12>
Parameters
value: number
Number to be written to buf.
@@ -729,7 +729,7 @@ when value is anything other than a signed integer.
writeUInt16BE
writeUInt16BE(value, offset?): number
Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer. Behavior is undefined when valueis anything other than an
unsigned 16-bit integer.
This function is also available under the writeUint16BE alias.
Writes value to buf at the specified offset as little-endian. The value must be a valid unsigned 16-bit integer. Behavior is undefined when value is
anything other than an unsigned 16-bit integer.
This function is also available under the writeUint16LE alias.
@@ -749,7 +749,7 @@ anything other than an unsigned 16-bit integer.
writeUInt32BE
writeUInt32BE(value, offset?): number
Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an
unsigned 32-bit integer.
This function is also available under the writeUint32BE alias.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeUInt32BE(0xfeedface, 0);
console.log(buf); // Prints: <Buffer fe ed fa ce>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeUInt32BE(0xfeedface, 0);
console.log(buf); // Prints: <Buffer fe ed fa ce>
Parameters
value: number
Number to be written to buf.
@@ -759,7 +759,7 @@ unsigned 32-bit integer.
writeUInt32LE
writeUInt32LE(value, offset?): number
Writes value to buf at the specified offset as little-endian. The value must be a valid unsigned 32-bit integer. Behavior is undefined when value is
anything other than an unsigned 32-bit integer.
This function is also available under the writeUint32LE alias.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeUInt32LE(0xfeedface, 0);
console.log(buf); // Prints: <Buffer ce fa ed fe>
+
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(4);
buf.writeUInt32LE(0xfeedface, 0);
console.log(buf); // Prints: <Buffer ce fa ed fe>
Parameters
value: number
Number to be written to buf.
@@ -770,7 +770,7 @@ anything other than an unsigned 32-bit integer.
valid unsigned 8-bit integer. Behavior is undefined when value is anything
other than an unsigned 8-bit integer.
This function is also available under the writeUint8 alias.
@@ -780,7 +780,7 @@ other than an unsigned 8-bit integer.
writeUIntBE
writeUIntBE(value, offset, byteLength): number
Writes byteLength bytes of value to buf at the specified offsetas big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
when value is anything other than an unsigned integer.
This function is also available under the writeUintBE alias.
@@ -791,7 +791,7 @@ when value is anything other than an unsigned integer.
writeUIntLE
writeUIntLE(value, offset, byteLength): number
Writes byteLength bytes of value to buf at the specified offsetas little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
when value is anything other than an unsigned integer.
This function is also available under the writeUintLE alias.
console.log(buf); // Prints: <Buffer ab 90 78 56 34 12>
Parameters
value: number
Number to be written to buf.
diff --git a/api/interfaces/_internal_.BufferConstructor.html b/api/interfaces/_internal_.BufferConstructor.html
index 0b7839ebc..ce1e00b0b 100644
--- a/api/interfaces/_internal_.BufferConstructor.html
+++ b/api/interfaces/_internal_.BufferConstructor.html
@@ -38,17 +38,17 @@ the given {ArrayBuffer}/{SharedArrayBuffer}.
for pooling. This value may be modified.
Calling Buffer.alloc() can be measurably slower than the alternative Buffer.allocUnsafe() but ensures that the newly created Buffer instance
@@ -62,7 +62,7 @@ data that might not have been allocated for Buffers.
Allocates a new Buffer of size bytes. If size is larger than constants.MAX_LENGTH or smaller than 0, ERR_OUT_OF_RANGE is thrown.
The underlying memory for Buffer instances created in this way is notinitialized. The contents of the newly created Buffer are unknown and may contain sensitive data. Use Buffer.alloc() instead to initializeBuffer instances with zeroes.
-
import { Buffer } from'node:buffer';
constbuf = Buffer.allocUnsafe(10);
console.log(buf); // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
A TypeError will be thrown if size is not a number.
@@ -92,7 +92,7 @@ many individual ArrayBuffer objects.
memory from a pool for an indeterminate amount of time, it may be appropriate
to create an un-pooled Buffer instance using Buffer.allocUnsafeSlow() and
then copying out the relevant bits.
-
import { Buffer } from'node:buffer';
// Need to keep around a few small chunks of memory. conststore = [];
socket.on('readable', () => { letdata; while (null !== (data = readable.read())) { // Allocate for retained data. constsb = Buffer.allocUnsafeSlow(10);
// Copy the data into the new allocation. data.copy(sb, 0, 0, 10);
store.push(sb); } });
+
import { Buffer } from'node:buffer';
// Need to keep around a few small chunks of memory. conststore = [];
socket.on('readable', () => { letdata; while (null !== (data = readable.read())) { // Allocate for retained data. constsb = Buffer.allocUnsafeSlow(10);
// Copy the data into the new allocation. data.copy(sb, 0, 0, 10);
store.push(sb); } });
A TypeError will be thrown if size is not a number.
@@ -105,7 +105,7 @@ for the encoding that is used to convert the string into bytes.
For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
return value might be greater than the length of a Buffer created from the
string.
-
console.log(arr.sort(Buffer.compare)); // Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ] // (This result is equal to: [buf2, buf1].)
Parameters
buf1: Uint8Array
buf2: Uint8Array
Returns -1 | 0 | 1
Either -1, 0, or 1, depending on the result of the comparison. See compare for details.
@@ -129,7 +129,7 @@ in list by adding their lengths.
If totalLength is provided, it is coerced to an unsigned integer. If the
combined length of the Buffers in list exceeds totalLength, the result is
truncated to totalLength.
-
import { Buffer } from'node:buffer';
// Create a single `Buffer` from a list of three `Buffer` instances.
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
// First listener myEmitter.on('event', functionfirstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', functionsecondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', functionthirdListener(...args) { constparameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); });
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener
+
// First listener myEmitter.on('event', functionfirstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', functionsecondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', functionthirdListener(...args) { constparameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); });
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener
@@ -49,13 +49,13 @@ in the list of the listeners of the event.
named eventName. No checks are made to see if the listener has already
been added. Multiple calls passing the same combination of eventName and
listener will result in the listener being added, and called, multiple times.
-
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
Adds a one-timelistener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
-
server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });
+
server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
@@ -79,7 +79,7 @@ event listener to the beginning of the listeners array.
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
-
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
-
server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
+
server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the EventEmitter, so that calls can be chained.
@@ -97,7 +97,7 @@ listener is removed, and then invoked.
// Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above constlisteners = emitter.rawListeners('log'); constlogFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener();
// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () =>console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above constnewListeners = emitter.rawListeners('log');
// Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above constlisteners = emitter.rawListeners('log'); constlogFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener();
// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () =>console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above constnewListeners = emitter.rawListeners('log');
removeListener() will remove, at most, one instance of a listener from the
@@ -118,7 +118,7 @@ called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution
will not remove them fromemit() in progress. Subsequent events behave as expected.
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
+
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
Because listeners are managed using an internal array, calling this will
@@ -129,7 +129,7 @@ the emitter.listeners() method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener() will remove the most
recently added instance. In the example the once('ping') listener is removed:
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
// First listener myEmitter.on('event', functionfirstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', functionsecondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', functionthirdListener(...args) { constparameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); });
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener
+
// First listener myEmitter.on('event', functionfirstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', functionsecondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', functionthirdListener(...args) { constparameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); });
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener
@@ -60,13 +60,13 @@ in the list of the listeners of the event.
named eventName. No checks are made to see if the listener has already
been added. Multiple calls passing the same combination of eventName and
listener will result in the listener being added, and called, multiple times.
-
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
Adds a one-timelistener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
-
server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });
+
server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
@@ -90,7 +90,7 @@ event listener to the beginning of the listeners array.
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
-
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
-
server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
+
server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the EventEmitter, so that calls can be chained.
@@ -108,7 +108,7 @@ listener is removed, and then invoked.
// Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above constlisteners = emitter.rawListeners('log'); constlogFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener();
// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () =>console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above constnewListeners = emitter.rawListeners('log');
// Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above constlisteners = emitter.rawListeners('log'); constlogFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener();
// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () =>console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above constnewListeners = emitter.rawListeners('log');
removeListener() will remove, at most, one instance of a listener from the
@@ -129,7 +129,7 @@ called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution
will not remove them fromemit() in progress. Subsequent events behave as expected.
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
+
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
Because listeners are managed using an internal array, calling this will
@@ -140,7 +140,7 @@ the emitter.listeners() method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener() will remove the most
recently added instance. In the example the once('ping') listener is removed:
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
// First listener myEmitter.on('event', functionfirstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', functionsecondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', functionthirdListener(...args) { constparameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); });
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener
+
// First listener myEmitter.on('event', functionfirstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', functionsecondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', functionthirdListener(...args) { constparameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); });
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener
@@ -52,13 +52,13 @@ in the list of the listeners of the event.
named eventName. No checks are made to see if the listener has already
been added. Multiple calls passing the same combination of eventName and
listener will result in the listener being added, and called, multiple times.
-
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
Adds a one-timelistener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
-
server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });
+
server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
@@ -82,7 +82,7 @@ event listener to the beginning of the listeners array.
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple times.
-
Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
-
server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
+
server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the EventEmitter, so that calls can be chained.
@@ -100,7 +100,7 @@ listener is removed, and then invoked.
// Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above constlisteners = emitter.rawListeners('log'); constlogFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener();
// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () =>console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above constnewListeners = emitter.rawListeners('log');
// Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above constlisteners = emitter.rawListeners('log'); constlogFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener();
// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () =>console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above constnewListeners = emitter.rawListeners('log');
removeListener() will remove, at most, one instance of a listener from the
@@ -121,7 +121,7 @@ called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution
will not remove them fromemit() in progress. Subsequent events behave as expected.
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
+
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
Because listeners are managed using an internal array, calling this will
@@ -132,7 +132,7 @@ the emitter.listeners() method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener() will remove the most
recently added instance. In the example the once('ping') listener is removed:
LiquidJS is a simple, expressive and safe Shopify / GitHub Pages compatible template engine in pure JavaScript. The purpose of this repo is to provide a standard Liquid implementation for the JavaScript community. Liquid is originally implemented in Ruby and used by GitHub Pages, Jekyll and Shopify, see Differences with Shopify/liquid.
-
LiquidJS syntax is relatively simple. There are 2 types of markups in LiquidJS:
+
Liquid is a template language originally implemented in Ruby and used by Shopify, Jekyll, and GitHub Pages. LiquidJS implements it in JavaScript; see Differences with Shopify/liquid for compatibility notes.
+
There are 2 types of markups in LiquidJS:
Tags. A tag consists of a tag name and optional arguments wrapped between {% and %}.
Outputs. An output consists of a value and a list of filters, which is optional, wrapped between {{ and }}.
A
@@ -156,7 +156,7 @@ is treated as length+end.Bufferor Uint8Array to copy into.