diff --git a/.all-contributorsrc b/.all-contributorsrc deleted file mode 100644 index f7c38afd67..0000000000 --- a/.all-contributorsrc +++ /dev/null @@ -1,756 +0,0 @@ -{ - "projectName": "liquidjs", - "projectOwner": "harttle", - "repoType": "github", - "repoHost": "https://github.com", - "files": [ - "README.md" - ], - "imageSize": 100, - "commit": false, - "commitConvention": "angular", - "contributors": [ - { - "login": "harttle", - "name": "Jun Yang", - "avatar_url": "https://avatars3.githubusercontent.com/u/4427974?v=4", - "profile": "https://harttle.land", - "contributions": [ - "maintenance", - "code" - ] - }, - { - "login": "chenos", - "name": "chenos", - "avatar_url": "https://avatars0.githubusercontent.com/u/2993310?v=4", - "profile": "https://github.com/chenos", - "contributions": [ - "code" - ] - }, - { - "login": "zachleat", - "name": "Zach Leatherman", - "avatar_url": "https://avatars2.githubusercontent.com/u/39355?v=4", - "profile": "https://zachleat.com/", - "contributions": [ - "bug" - ] - }, - { - "login": "thardy", - "name": "Tim Hardy", - "avatar_url": "https://avatars3.githubusercontent.com/u/120636?v=4", - "profile": "https://github.com/thardy", - "contributions": [ - "code" - ] - }, - { - "login": "paulrobertlloyd", - "name": "Paul Robert Lloyd", - "avatar_url": "https://avatars3.githubusercontent.com/u/813383?v=4", - "profile": "https://paulrobertlloyd.com/", - "contributions": [ - "code", - "bug" - ] - }, - { - "login": "aleclarson", - "name": "Alec Larson", - "avatar_url": "https://avatars2.githubusercontent.com/u/1925840?v=4", - "profile": "https://twitter.com/alecdotbiz", - "contributions": [ - "code" - ] - }, - { - "login": "pmalouin", - "name": "Patrick Malouin", - "avatar_url": "https://avatars1.githubusercontent.com/u/1411117?v=4", - "profile": "https://github.com/pmalouin", - "contributions": [ - "code", - "doc" - ] - }, - { - "login": "jaswrks", - "name": "jaswrks", - "avatar_url": "https://avatars3.githubusercontent.com/u/1563559?v=4", - "profile": "https://jaswrks.com", - "contributions": [ - "code" - ] - }, - { - "login": "oott123", - "name": "三三", - "avatar_url": "https://avatars2.githubusercontent.com/u/905663?v=4", - "profile": "https://oott123.com", - "contributions": [ - "code", - "ideas" - ] - }, - { - "login": "ssendev", - "name": "ssendev", - "avatar_url": "https://avatars0.githubusercontent.com/u/450793?v=4", - "profile": "https://github.com/ssendev", - "contributions": [ - "code", - "doc" - ] - }, - { - "login": "wojtask9", - "name": "wojtask9", - "avatar_url": "https://avatars3.githubusercontent.com/u/6099236?v=4", - "profile": "https://github.com/wojtask9", - "contributions": [ - "code" - ] - }, - { - "login": "thelornenelson", - "name": "Andrew Barclay", - "avatar_url": "https://avatars3.githubusercontent.com/u/24596583?v=4", - "profile": "https://github.com/thelornenelson", - "contributions": [ - "code" - ] - }, - { - "login": "cmawhorter", - "name": "Cory Mawhorter", - "avatar_url": "https://avatars2.githubusercontent.com/u/142338?v=4", - "profile": "https://www.stam.pr/", - "contributions": [ - "code" - ] - }, - { - "login": "thehappybug", - "name": "Mehdi Jaffery", - "avatar_url": "https://avatars0.githubusercontent.com/u/3393530?v=4", - "profile": "https://github.com/thehappybug", - "contributions": [ - "code" - ] - }, - { - "login": "robinbijlani", - "name": "Robin Bijlani", - "avatar_url": "https://avatars0.githubusercontent.com/u/2503108?v=4", - "profile": "https://github.com/robinbijlani", - "contributions": [ - "code", - "bug" - ] - }, - { - "login": "ryaninvents", - "name": "Ryan Kennedy", - "avatar_url": "https://avatars3.githubusercontent.com/u/8356669?v=4", - "profile": "https://www.rmkennedy.com", - "contributions": [ - "code" - ] - }, - { - "login": "strax", - "name": "Sami Kukkonen", - "avatar_url": "https://avatars2.githubusercontent.com/u/587213?v=4", - "profile": "https://github.com/strax", - "contributions": [ - "code" - ] - }, - { - "login": "ScottFreeCode", - "name": "Scott Santucci", - "avatar_url": "https://avatars3.githubusercontent.com/u/16506071?v=4", - "profile": "https://ScottFreeCode.github.io/", - "contributions": [ - "code" - ] - }, - { - "login": "stevenanthonyrevo", - "name": "Steven ", - "avatar_url": "https://avatars3.githubusercontent.com/u/8505293?v=4", - "profile": "http://stevenrescigno.com", - "contributions": [ - "example", - "code" - ] - }, - { - "login": "azu", - "name": "azu", - "avatar_url": "https://avatars1.githubusercontent.com/u/19714?v=4", - "profile": "https://efcl.info/", - "contributions": [ - "doc" - ] - }, - { - "login": "wyozi", - "name": "Joonas", - "avatar_url": "https://avatars3.githubusercontent.com/u/4894573?v=4", - "profile": "https://github.com/wyozi", - "contributions": [ - "code" - ] - }, - { - "login": "jamelait", - "name": "Jamel A.", - "avatar_url": "https://avatars1.githubusercontent.com/u/14369255?v=4", - "profile": "https://github.com/jamelait", - "contributions": [ - "code" - ] - }, - { - "login": "brandonpittman", - "name": "Brandon Pittman", - "avatar_url": "https://avatars0.githubusercontent.com/u/967145?v=4", - "profile": "https://brandonpittman.net", - "contributions": [ - "code" - ] - }, - { - "login": "tgrandgent", - "name": "tgrandgent", - "avatar_url": "https://avatars3.githubusercontent.com/u/17069042?v=4", - "profile": "https://github.com/tgrandgent", - "contributions": [ - "code" - ] - }, - { - "login": "mastodon0", - "name": "Martin Schuster", - "avatar_url": "https://avatars1.githubusercontent.com/u/7924332?v=4", - "profile": "https://github.com/mastodon0", - "contributions": [ - "code" - ] - }, - { - "login": "richardo2016", - "name": "Ray", - "avatar_url": "https://avatars0.githubusercontent.com/u/6339390?v=4", - "profile": "http://js.chenlei.me", - "contributions": [ - "test", - "code" - ] - }, - { - "login": "CriGoT", - "name": "Cristofer Gonzales", - "avatar_url": "https://avatars0.githubusercontent.com/u/1936786?v=4", - "profile": "https://github.com/CriGoT", - "contributions": [ - "code" - ] - }, - { - "login": "cfjedimaster", - "name": "Raymond Camden", - "avatar_url": "https://avatars3.githubusercontent.com/u/393660?v=4", - "profile": "https://www.raymondcamden.com", - "contributions": [ - "doc" - ] - }, - { - "login": "stedman", - "name": "Steve Stedman", - "avatar_url": "https://avatars1.githubusercontent.com/u/183122?v=4", - "profile": "https://stedman.dev", - "contributions": [ - "doc" - ] - }, - { - "login": "aciccarello", - "name": "Anthony Ciccarello", - "avatar_url": "https://avatars0.githubusercontent.com/u/11273838?v=4", - "profile": "https://ciccarello.me", - "contributions": [ - "doc" - ] - }, - { - "login": "TrySound", - "name": "Bogdan Chadkin", - "avatar_url": "https://avatars0.githubusercontent.com/u/5635476?v=4", - "profile": "https://twitter.com/IAmTrySound", - "contributions": [ - "code" - ] - }, - { - "login": "tejasmanohar", - "name": "Tejas Manohar", - "avatar_url": "https://avatars0.githubusercontent.com/u/5959235?v=4", - "profile": "https://hightouch.io", - "contributions": [ - "code" - ] - }, - { - "login": "pdehaan", - "name": "Peter deHaan", - "avatar_url": "https://avatars2.githubusercontent.com/u/557895?v=4", - "profile": "http://about.me/peterdehaan", - "contributions": [ - "doc" - ] - }, - { - "login": "amit777", - "name": "amit777", - "avatar_url": "https://avatars0.githubusercontent.com/u/2703309?v=4", - "profile": "https://github.com/amit777", - "contributions": [ - "code" - ] - }, - { - "login": "sschuldenzucker", - "name": "Steffen Schuldenzucker", - "avatar_url": "https://avatars3.githubusercontent.com/u/1100776?v=4", - "profile": "http://www.ifi.uzh.ch/en/ce/people/schuldenzucker.html", - "contributions": [ - "code" - ] - }, - { - "login": "Pixcell", - "name": "Pixcell", - "avatar_url": "https://avatars0.githubusercontent.com/u/4005291?v=4", - "profile": "https://github.com/Pixcell", - "contributions": [ - "code" - ] - }, - { - "login": "JasonEtco", - "name": "Jason Etcovitch", - "avatar_url": "https://avatars.githubusercontent.com/u/10660468?v=4", - "profile": "https://jasonet.co", - "contributions": [ - "code" - ] - }, - { - "login": "kayuapi", - "name": "ZC", - "avatar_url": "https://avatars.githubusercontent.com/u/10304328?v=4", - "profile": "https://github.com/kayuapi", - "contributions": [ - "doc" - ] - }, - { - "login": "mems", - "name": "Memmie Lenglet", - "avatar_url": "https://avatars.githubusercontent.com/u/729275?v=4", - "profile": "https://memmie.lenglet.name", - "contributions": [ - "code" - ] - }, - { - "login": "ilhamdev0", - "name": "ilhamdev0", - "avatar_url": "https://avatars.githubusercontent.com/u/57636145?v=4", - "profile": "https://github.com/ilhamdev0", - "contributions": [ - "doc" - ] - }, - { - "login": "c412216887", - "name": "一饮一啄皆是人生", - "avatar_url": "https://avatars.githubusercontent.com/u/29691650?v=4", - "profile": "https://github.com/c412216887", - "contributions": [ - "doc" - ] - }, - { - "login": "labnol", - "name": "Amit Agarwal", - "avatar_url": "https://avatars.githubusercontent.com/u/1344071?v=4", - "profile": "https://digitalinspiration.com/", - "contributions": [ - "doc" - ] - }, - { - "login": "n1ru4l", - "name": "Laurin Quast", - "avatar_url": "https://avatars.githubusercontent.com/u/14338007?v=4", - "profile": "https://n1ru4l.cloud/", - "contributions": [ - "code" - ] - }, - { - "login": "mattvague", - "name": "Matt Vague", - "avatar_url": "https://avatars.githubusercontent.com/u/64985?v=4", - "profile": "https://github.com/mattvague", - "contributions": [ - "code" - ] - }, - { - "login": "bglw", - "name": "Liam Bigelow", - "avatar_url": "https://avatars.githubusercontent.com/u/40188355?v=4", - "profile": "https://github.com/bglw", - "contributions": [ - "code" - ] - }, - { - "login": "JaKXz", - "name": "Jason Kurian", - "avatar_url": "https://avatars.githubusercontent.com/u/2642545?v=4", - "profile": "https://about.me/jasonkurian", - "contributions": [ - "doc" - ] - }, - { - "login": "dphm", - "name": "d pham (they/them)", - "avatar_url": "https://avatars.githubusercontent.com/u/1707217?v=4", - "profile": "https://github.com/dphm", - "contributions": [ - "doc" - ] - }, - { - "login": "AleksandrHovhannisyan", - "name": "Aleksandr Hovhannisyan", - "avatar_url": "https://avatars.githubusercontent.com/u/19352442?v=4", - "profile": "https://www.aleksandrhovhannisyan.com/", - "contributions": [ - "code" - ] - }, - { - "login": "jg-rp", - "name": "jg-rp", - "avatar_url": "https://avatars.githubusercontent.com/u/72664870?v=4", - "profile": "https://github.com/jg-rp", - "contributions": [ - "code" - ] - }, - { - "login": "ameyaapte1", - "name": "Ameya Apte", - "avatar_url": "https://avatars.githubusercontent.com/u/16054747?v=4", - "profile": "https://github.com/ameyaapte1", - "contributions": [ - "code" - ] - }, - { - "login": "tbdrz", - "name": "tbdrz", - "avatar_url": "https://avatars.githubusercontent.com/u/50599116?v=4", - "profile": "https://github.com/tbdrz", - "contributions": [ - "doc" - ] - }, - { - "login": "santialbo", - "name": "Santi Albo", - "avatar_url": "https://avatars.githubusercontent.com/u/1557563?v=4", - "profile": "http://santialbo.com", - "contributions": [ - "doc", - "code" - ] - }, - { - "login": "YahangWu", - "name": "Yahang Wu", - "avatar_url": "https://avatars.githubusercontent.com/u/12295975?v=4", - "profile": "https://github.com/YahangWu", - "contributions": [ - "doc" - ] - }, - { - "login": "hongl-1", - "name": "hongl", - "avatar_url": "https://avatars.githubusercontent.com/u/101576612?v=4", - "profile": "https://github.com/hongl-1", - "contributions": [ - "doc" - ] - }, - { - "login": "zxx-457", - "name": "zxx-457", - "avatar_url": "https://avatars.githubusercontent.com/u/114141362?v=4", - "profile": "https://github.com/zxx-457", - "contributions": [ - "doc" - ] - }, - { - "login": "prassie", - "name": "prassie", - "avatar_url": "https://avatars.githubusercontent.com/u/1357831?v=4", - "profile": "https://github.com/prassie", - "contributions": [ - "doc" - ] - }, - { - "login": "slavivanov", - "name": "Slav Ivanov", - "avatar_url": "https://avatars.githubusercontent.com/u/713329?v=4", - "profile": "http://slavv.com/", - "contributions": [ - "code" - ] - }, - { - "login": "DaRosenberg", - "name": "Daniel Rosenberg", - "avatar_url": "https://avatars.githubusercontent.com/u/3889090?v=4", - "profile": "http://www.orgflow.io/", - "contributions": [ - "code" - ] - }, - { - "login": "bobgubko", - "name": "bobgubko", - "avatar_url": "https://avatars.githubusercontent.com/u/733312?v=4", - "profile": "https://github.com/bobgubko", - "contributions": [ - "code" - ] - }, - { - "login": "bangank36", - "name": "BaNgan", - "avatar_url": "https://avatars.githubusercontent.com/u/10071857?v=4", - "profile": "https://github.com/bangank36", - "contributions": [ - "doc" - ] - }, - { - "login": "mahyar-pasarzangene", - "name": "Mahyar Pasarzangene", - "avatar_url": "https://avatars.githubusercontent.com/u/16485039?v=4", - "profile": "https://github.com/mahyar-pasarzangene", - "contributions": [ - "doc" - ] - }, - { - "login": "TomasHubelbauer", - "name": "Tomáš Hübelbauer", - "avatar_url": "https://avatars.githubusercontent.com/u/6831144?v=4", - "profile": "https://hubelbauer.net/", - "contributions": [ - "code", - "doc" - ] - }, - { - "login": "jgarber623", - "name": "Jason Garber", - "avatar_url": "https://avatars.githubusercontent.com/u/73866?v=4", - "profile": "https://sixtwothree.org", - "contributions": [ - "code" - ] - }, - { - "login": "NReilingh", - "name": "Nick Reilingh", - "avatar_url": "https://avatars.githubusercontent.com/u/2458645?v=4", - "profile": "http://nickreilingh.com/", - "contributions": [ - "doc" - ] - }, - { - "login": "ebobby", - "name": "Francisco Soto", - "avatar_url": "https://avatars.githubusercontent.com/u/170356?v=4", - "profile": "http://ebobby.org", - "contributions": [ - "code" - ] - }, - { - "login": "davidlj95", - "name": "David LJ", - "avatar_url": "https://avatars.githubusercontent.com/u/8050648?v=4", - "profile": "https://www.davidlj95.com", - "contributions": [ - "doc" - ] - }, - { - "login": "RasmusWL", - "name": "Rasmus Wriedt Larsen", - "avatar_url": "https://avatars.githubusercontent.com/u/1054041?v=4", - "profile": "https://github.com/RasmusWL", - "contributions": [ - "doc" - ] - }, - { - "login": "brunodccarvalho", - "name": "Bruno Carvalho", - "avatar_url": "https://avatars.githubusercontent.com/u/24962950?v=4", - "profile": "https://github.com/brunodccarvalho", - "contributions": [ - "code" - ] - }, - { - "login": "fupengl", - "name": "傅鹏", - "avatar_url": "https://avatars.githubusercontent.com/u/20211964?v=4", - "profile": "https://github.com/fupengl", - "contributions": [ - "code" - ] - }, - { - "login": "joel-hamilton", - "name": "Joel Hamilton", - "avatar_url": "https://avatars.githubusercontent.com/u/12899024?v=4", - "profile": "https://github.com/joel-hamilton", - "contributions": [ - "code" - ] - }, - { - "login": "amedve", - "name": "Max Medve", - "avatar_url": "https://avatars.githubusercontent.com/u/23156422?v=4", - "profile": "https://github.com/amedve", - "contributions": [ - "code" - ] - }, - { - "login": "cossssmin", - "name": "Cosmin Popovici", - "avatar_url": "https://avatars.githubusercontent.com/u/1656595?v=4", - "profile": "https://maizzle.com", - "contributions": [ - "doc" - ] - }, - { - "login": "admtnnr", - "name": "Adam Tanner", - "avatar_url": "https://avatars.githubusercontent.com/u/27502?v=4", - "profile": "https://github.com/admtnnr", - "contributions": [ - "code" - ] - }, - { - "login": "GuillermoCasalCaro", - "name": "Guillermo Casal Caro", - "avatar_url": "https://avatars.githubusercontent.com/u/18685581?v=4", - "profile": "https://github.com/GuillermoCasalCaro", - "contributions": [ - "code" - ] - }, - { - "login": "jsoref", - "name": "Josh Soref", - "avatar_url": "https://avatars.githubusercontent.com/u/2119212?v=4", - "profile": "https://github.com/jsoref", - "contributions": [ - "doc" - ] - }, - { - "login": "vrugtehagel", - "name": "Koen", - "avatar_url": "https://avatars.githubusercontent.com/u/41021050?v=4", - "profile": "https://vrugtehagel.nl", - "contributions": [ - "code" - ] - }, - { - "login": "Neamar", - "name": "Matthieu Bacconnier", - "avatar_url": "https://avatars.githubusercontent.com/u/536844?v=4", - "profile": "https://neamar.fr", - "contributions": [ - "doc" - ] - }, - { - "login": "timvandam", - "name": "Tim van Dam", - "avatar_url": "https://avatars.githubusercontent.com/u/35376389?v=4", - "profile": "https://tovd.dev", - "contributions": [ - "code" - ] - }, - { - "login": "edh649", - "name": "Ed Hanton", - "avatar_url": "https://avatars.githubusercontent.com/u/527604?v=4", - "profile": "https://github.com/edh649", - "contributions": [ - "doc" - ] - }, - { - "login": "gurdiga", - "name": "Vlad GURDIGA", - "avatar_url": "https://avatars.githubusercontent.com/u/53922?v=4", - "profile": "https://gurdiga.com", - "contributions": [ - "doc" - ] - }, - { - "login": "StreakingMan", - "name": "裸奔狂甩丁丁", - "avatar_url": "https://avatars.githubusercontent.com/u/30397306?v=4", - "profile": "https://www.streakingman.com", - "contributions": [ - "doc" - ] - } - ], - "contributorsPerLine": 7, - "skipCi": true, - "commitType": "docs" -} diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 5913fb120b..0000000000 --- a/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -node_modules -dist -demo -coverage -docs -private.* diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 1438fa7729..0000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "extends": ["standard", "plugin:@typescript-eslint/recommended"], - "env": { - "mocha": true, - "es6": true, - "browser": true, - "node": true - }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "tsconfig.json" - }, - "plugins": [ - "deprecation", - "mocha", - "standard", - "@typescript-eslint", - "promise" - ], - "rules": { - "deprecation/deprecation": "error", - "no-var": 2, - "prefer-const": 2, - "no-unused-vars": "off", - "indent": "off", - "no-mixed-operators": "off", - "no-dupe-class-members": "off", - "no-useless-constructor": "off", - "@typescript-eslint/indent": ["error", 2], - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-object-literal-type-assertion": "off", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/interface-name-prefix": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "import/export": "off", - "@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }] - }, - "overrides": [{ - "files": ["**/filters/*.ts"], - "rules": { - "camelcase": "off" - } - }, { - "files": ["**/*.js", "**/*.mjs"], - "rules": { - "@typescript-eslint/no-var-requires": "off" - } - }, { - "files": ["test/**/*.ts"], - "rules": { - "deprecation/deprecation": "off" - } - }] -} diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 1f9b80d929..0000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: harttle -# patreon: harttle -open_collective: liquidjs -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 0e23c1cbf3..0000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Build -on: - workflow_call: - inputs: - os: - required: true - type: string - bundles: - required: false - type: string -env: - BUNDLES: ${{ inputs.bundles }} -jobs: - build: - name: Build - runs-on: ${{ inputs.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' - - name: Install dependencies - run: npm ci - - name: Build - run: npm run build - - name: Archive artifacts - uses: actions/upload-artifact@v4 - with: - name: dist-${{ inputs.os }} - path: dist - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: npm-logs-${{ inputs.os }} - path: ~/.npm/_logs diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml deleted file mode 100644 index 3f41a8bc42..0000000000 --- a/.github/workflows/ci-build.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: CI Build -on: - push: - branches: - - 'master' - - 'test' -jobs: - build: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - uses: ./.github/workflows/build.yml - with: - os: ${{ matrix.os }} - lint: - uses: ./.github/workflows/lint.yml - test: - needs: build - uses: ./.github/workflows/test.yml - coverage: - uses: ./.github/workflows/coverage.yml - performance: - needs: build - uses: ./.github/workflows/performance.yml - with: - os: ubuntu-latest - docs: - uses: ./.github/workflows/docs.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index af777f01ca..0000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Test Coverage -on: [workflow_dispatch, workflow_call] -jobs: - coverage: - name: Test Coverage - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '22' - - name: Install dependencies - run: npm ci - - name: Test - run: npm run test:coverage - - name: Coverage - uses: coverallsapp/github-action@v1.1.2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: npm-logs - path: ~/.npm/_logs diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index b1d09df01d..0000000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Docs -on: [workflow_dispatch, workflow_call] -jobs: - docs: - name: Docs - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' - - name: Build - run: | - npm ci - npm run build:docs - - name: Publish - if: github.ref == 'refs/heads/master' - uses: JamesIves/github-pages-deploy-action@4.1.4 - with: - branch: gh-pages - folder: docs/public - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: npm-logs - path: ~/.npm/_logs \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 23b031950a..0000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Lint -on: [workflow_dispatch, workflow_call] -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' - - name: Install dependencies - run: npm ci - - name: Lint - run: npm run lint - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: npm-logs - path: ~/.npm/_logs diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml deleted file mode 100644 index aeee66c7e5..0000000000 --- a/.github/workflows/performance.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Performance Check -on: - workflow_call: - inputs: - os: - required: true - type: string -jobs: - performance: - name: Performance - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: dist-${{ inputs.os }} - path: dist - - name: Check Performance - run: npm run perf:diff - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: npm-logs - path: ~/.npm/_logs diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml deleted file mode 100644 index 5db01eb0b1..0000000000 --- a/.github/workflows/pr-build.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: PR Build -on: pull_request -jobs: - build: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - uses: ./.github/workflows/build.yml - with: - os: ${{ matrix.os }} - lint: - uses: ./.github/workflows/lint.yml - test: - needs: build - uses: ./.github/workflows/test.yml - coverage: - uses: ./.github/workflows/coverage.yml - performance: - needs: build - uses: ./.github/workflows/performance.yml - with: - os: ubuntu-latest \ No newline at end of file diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml deleted file mode 100644 index 165949dc03..0000000000 --- a/.github/workflows/pr-check.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: PR Check -on: - pull_request_target: - types: - - opened - - edited -jobs: - title: - name: Check PR title - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 7b13b8fdf8..0000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Release -on: workflow_dispatch -jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '14' - - name: Install Dependencies - run: npm ci - - name: Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: | - if [ ${{ github.ref == 'refs/heads/master' }} ]; then - npx semantic-release - else - npx semantic-release --dry-run - fi - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: npm-logs - path: ~/.npm/_logs \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index ca4939661a..0000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Test -on: [workflow_dispatch, workflow_call] -jobs: - test: - name: Test - strategy: - matrix: - os: [ubuntu-latest] - timezone: [Etc/GMT, Asia/Shanghai, America/New_York] - node-version: [22] - include: - - os: macos-latest - timezone: America/New_York - node-versoin: 22 - - os: ubuntu-latest - timezone: Etc/GMT - node-version: 16 - - os: ubuntu-latest - timezone: Asia/Shanghai - node-version: 15 - - os: ubuntu-latest - timezone: Asia/Shanghai - node-version: 14 - runs-on: ${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: npm ci - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: dist-${{ matrix.os }} - path: dist - - name: Run Test - run: TZ=${{ matrix.timezone }} npm test - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: test-npm-logs-${{ matrix.os }}-${{ matrix.timezone }}-${{ matrix.node-version }} - path: ~/.npm/_logs - demo: - name: Demo Check - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: 22 - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: dist-ubuntu-latest - path: dist - - name: Run Demo Test - run: npm run test:demo - - name: Archive npm failure logs - uses: actions/upload-artifact@v4 - if: failure() - with: - name: demo-npm-logs - path: ~/.npm/_logs diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f86209f36f..0000000000 --- a/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# logs -*.log -npm-debug.log* - -# cache -.rpt2_cache -coverage/ -.nyc_output/ - -# modules -node_modules/ - -# tmp -docs/public/js/liquid.browser.min.js -docs/themes/navy/layout/partial/all-contributors.swig -docs/themes/navy/layout/partial/financial-contributors.swig -dist/ -demo/*/yarn.json - -# editors -.*.swp -.vscode - diff --git a/.mocharc.js b/.mocharc.js deleted file mode 100644 index d20fb3d76b..0000000000 --- a/.mocharc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - require: "ts-node/register/transpile-only", - reporter: "spec" -} diff --git a/.nycrc.json b/.nycrc.json deleted file mode 100644 index ba50746de3..0000000000 --- a/.nycrc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "exclude": ["dist", "test"], - "reporter": ["html", "lcov"] -} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 068378e2f4..0000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,1469 +0,0 @@ -## [10.21.1](https://github.com/harttle/liquidjs/compare/v10.21.0...v10.21.1) (2025-05-14) - - -### Bug Fixes - -* block.super with strictVariables, [#806](https://github.com/harttle/liquidjs/issues/806) ([#807](https://github.com/harttle/liquidjs/issues/807)) ([025c40f](https://github.com/harttle/liquidjs/commit/025c40f0f2f13efa62193c61d2fa56943917ac3c)) - -# [10.21.0](https://github.com/harttle/liquidjs/compare/v10.20.3...v10.21.0) (2025-02-23) - - -### Features - -* add find_index, has, and reject filters ([#799](https://github.com/harttle/liquidjs/issues/799)) ([0deb93e](https://github.com/harttle/liquidjs/commit/0deb93eeae4f530901e9a7d099bcc47207ad7385)) - -## [10.20.3](https://github.com/harttle/liquidjs/compare/v10.20.2...v10.20.3) (2025-02-09) - - -### Bug Fixes - -* empty tagToken.args since 10.20.0, fixes [#796](https://github.com/harttle/liquidjs/issues/796) ([38a0f51](https://github.com/harttle/liquidjs/commit/38a0f510b0a14baf35a368e9f07b536253394d06)) - -## [10.20.2](https://github.com/harttle/liquidjs/compare/v10.20.1...v10.20.2) (2025-01-19) - - -### Bug Fixes - -* consistent range syntax parsing, [#791](https://github.com/harttle/liquidjs/issues/791) ([a490a70](https://github.com/harttle/liquidjs/commit/a490a70da1ca2b479065c6618207bf4789db6b4f)) -* context for group_by_exp/where_exp/find_exp, [#790](https://github.com/harttle/liquidjs/issues/790) ([a5070af](https://github.com/harttle/liquidjs/commit/a5070af3e4b4d1ae3b6398c6638b130e50e1cf6e)) - -## [10.20.1](https://github.com/harttle/liquidjs/compare/v10.20.0...v10.20.1) (2025-01-04) - - -### Bug Fixes - -* break/continue stops whole template, [#783](https://github.com/harttle/liquidjs/issues/783) ([5f1a4cf](https://github.com/harttle/liquidjs/commit/5f1a4cfdc9d6bde31ce86ddc88b8f4bdf52f7893)) -* enumerate plain objects in where/where_exp, [#785](https://github.com/harttle/liquidjs/issues/785) ([#788](https://github.com/harttle/liquidjs/issues/788)) ([25ef104](https://github.com/harttle/liquidjs/commit/25ef104446731f4b6cb3a2e78f4d3b99efb635f4)) -* preserveTimezones support for RFC2822 date, [#784](https://github.com/harttle/liquidjs/issues/784) ([59cf3c0](https://github.com/harttle/liquidjs/commit/59cf3c08dbc5f2e5b109ffcb5375ae738b5ac386)) - -# [10.20.0](https://github.com/harttle/liquidjs/compare/v10.19.1...v10.20.0) (2024-12-28) - - -### Features - -* `size`, `first`, `last` support arraylike objects, [#781](https://github.com/harttle/liquidjs/issues/781) ([35a8442](https://github.com/harttle/liquidjs/commit/35a84421a622b3a6657946b9395839da2b8e154a)) -* static variable analysis ([#770](https://github.com/harttle/liquidjs/issues/770)) ([3492ff6](https://github.com/harttle/liquidjs/commit/3492ff63f40abb8ff8adb8b6b0ce29408f99e19b)) - -## [10.19.1](https://github.com/harttle/liquidjs/compare/v10.19.0...v10.19.1) (2024-12-22) - - -### Bug Fixes - -* add sideEffects=false to package.json ([734eb52](https://github.com/harttle/liquidjs/commit/734eb52b987d46d33cf8f03281a3773a0f1f0e4a)) -* inconsistent continue behaviour, fixes [#779](https://github.com/harttle/liquidjs/issues/779) ([e3ef574](https://github.com/harttle/liquidjs/commit/e3ef574674c5a21a37b3ffc929f514c8a3d0b866)) -* memoryLimit doesn't work in for tag, [#776](https://github.com/harttle/liquidjs/issues/776) ([2af297f](https://github.com/harttle/liquidjs/commit/2af297f81ac465feb3277ba7b92f7236409370b0)) - -# [10.19.0](https://github.com/harttle/liquidjs/compare/v10.18.0...v10.19.0) (2024-11-17) - - -### Features - -* allow drops in property access ([#769](https://github.com/harttle/liquidjs/issues/769)) ([11f013b](https://github.com/harttle/liquidjs/commit/11f013bf249f1366306c1f0d728d45a95eb2df1a)) -* support Jekyll style `where`, [#768](https://github.com/harttle/liquidjs/issues/768) ([9107eb1](https://github.com/harttle/liquidjs/commit/9107eb1b93f5c11dca0ee0f0d2c1c8243849c3ab)) - -# [10.18.0](https://github.com/harttle/liquidjs/compare/v10.17.0...v10.18.0) (2024-10-16) - - -### Features - -* expose FilterToken to filter `this`, [#762](https://github.com/harttle/liquidjs/issues/762) ([d705888](https://github.com/harttle/liquidjs/commit/d705888c8d46d9dd95fcb41c0fb7bfbaf647eddd)) - -# [10.17.0](https://github.com/harttle/liquidjs/compare/v10.16.7...v10.17.0) (2024-09-22) - - -### Features - -* support custom key-value separator, [#752](https://github.com/harttle/liquidjs/issues/752) ([6aeed25](https://github.com/harttle/liquidjs/commit/6aeed2586a70a5bd4f878d2cb32547e35677458d)) - -## [10.16.7](https://github.com/harttle/liquidjs/compare/v10.16.6...v10.16.7) (2024-08-29) - - -### Bug Fixes - -* use CommonJS bundle to support default export ([2543461](https://github.com/harttle/liquidjs/commit/25434618808d8ab437ce4606d59114b4ad849f7f)) -* use cwd to resolve npm partials for Node.JS ([e5fbdfe](https://github.com/harttle/liquidjs/commit/e5fbdfe43415c9f78408f1349873c0011f639d82)) - -## [10.16.6](https://github.com/harttle/liquidjs/compare/v10.16.5...v10.16.6) (2024-08-29) - - -### Bug Fixes - -* expose originalError from LiquidError, [#742](https://github.com/harttle/liquidjs/issues/742) ([86f6bf0](https://github.com/harttle/liquidjs/commit/86f6bf0d3198354af23bcdb298c6625a6c5a4dde)) - -## [10.16.5](https://github.com/harttle/liquidjs/compare/v10.16.4...v10.16.5) (2024-08-27) - - -### Bug Fixes - -* ESM bundle for Node.js, [#739](https://github.com/harttle/liquidjs/issues/739) ([ce84cd6](https://github.com/harttle/liquidjs/commit/ce84cd6f43c8e076ce9d2507b2b7f3395fcd1328)) - -## [10.16.4](https://github.com/harttle/liquidjs/compare/v10.16.3...v10.16.4) (2024-08-23) - - -### Bug Fixes - -* "filter is not a function" for uniq ([68387c3](https://github.com/harttle/liquidjs/commit/68387c31ead77862a634f857a64932ef07b85188)) -* memory limit issue for join filter, fix [#737](https://github.com/harttle/liquidjs/issues/737) ([2d59cff](https://github.com/harttle/liquidjs/commit/2d59cff0a6162b462b4d97ebea4e0dbaf6146b65)) - -## [10.16.3](https://github.com/harttle/liquidjs/compare/v10.16.2...v10.16.3) (2024-08-16) - - -### Bug Fixes - -* support for NodeJS 15, fixes [#732](https://github.com/harttle/liquidjs/issues/732) ([4548c11](https://github.com/harttle/liquidjs/commit/4548c1140629bf270d163a403c2994d785c7f710)) - -## [10.16.2](https://github.com/harttle/liquidjs/compare/v10.16.1...v10.16.2) (2024-08-15) - - -### Bug Fixes - -* support for NodeJS 14 ([85bd0d3](https://github.com/harttle/liquidjs/commit/85bd0d35a6d949a02db49ba546407fe5be17db5e)) - -## [10.16.1](https://github.com/harttle/liquidjs/compare/v10.16.0...v10.16.1) (2024-07-25) - - -### Bug Fixes - -* parser throws on non-string input, [#726](https://github.com/harttle/liquidjs/issues/726) ([21a8223](https://github.com/harttle/liquidjs/commit/21a822348f3c315dae56fba2674ad3db0cf2f80d)) - -# [10.16.0](https://github.com/harttle/liquidjs/compare/v10.15.0...v10.16.0) (2024-07-21) - - -### Features - -* locale support for date filter, [#567](https://github.com/harttle/liquidjs/issues/567) ([#723](https://github.com/harttle/liquidjs/issues/723)) ([e4aeb02](https://github.com/harttle/liquidjs/commit/e4aeb023fddf5ead90db209599cfd99450274658)) - -# [10.15.0](https://github.com/harttle/liquidjs/compare/v10.14.0...v10.15.0) (2024-07-09) - - -### Bug Fixes - -* report error for malformed else/elsif/endif/endfor, [#713](https://github.com/harttle/liquidjs/issues/713) ([22b5a12](https://github.com/harttle/liquidjs/commit/22b5a123333a066aaf7dff580df061e7cd6aa7b2)) - - -### Features - -* DoS prevention, [#250](https://github.com/harttle/liquidjs/issues/250) ([e443068](https://github.com/harttle/liquidjs/commit/e443068cb9281883ff0fe9f755a15f52ada4e7e2)) -* support in-memory template mapping, inspired by [@jg-rp](https://github.com/jg-rp) [#714](https://github.com/harttle/liquidjs/issues/714) ([df27ac6](https://github.com/harttle/liquidjs/commit/df27ac694739496982012432077fe28b1476662a)) - -# [10.14.0](https://github.com/harttle/liquidjs/compare/v10.13.1...v10.14.0) (2024-06-17) - - -### Bug Fixes - -* use drop `valueOf` when evaluated as condition ([#705](https://github.com/harttle/liquidjs/issues/705)) ([a7da93f](https://github.com/harttle/liquidjs/commit/a7da93ff0f2c1c66f9c85b45ffcc1326c23254c7)) - - -### Features - -* support catching all errors, [#220](https://github.com/harttle/liquidjs/issues/220) ([#710](https://github.com/harttle/liquidjs/issues/710)) ([3b5627b](https://github.com/harttle/liquidjs/commit/3b5627b04072b1d6703ef5ba782a3a0f26fd2a60)) - -## [10.13.1](https://github.com/harttle/liquidjs/compare/v10.13.0...v10.13.1) (2024-05-24) - - -### Bug Fixes - -* allow liquidMethodMissing to return any supported value type ([#698](https://github.com/harttle/liquidjs/issues/698)) ([0983f2c](https://github.com/harttle/liquidjs/commit/0983f2c42012b2b97258d0cdcb07b6d43c904814)) -* isComparable full interface check ([#701](https://github.com/harttle/liquidjs/issues/701)) ([55e144a](https://github.com/harttle/liquidjs/commit/55e144a0298047349d55d8483a46b2513303d940)) - -# [10.13.0](https://github.com/harttle/liquidjs/compare/v10.12.0...v10.13.0) (2024-05-13) - - -### Features - -* array_to_sentence_string and number_of_words filters from Jekyll, [#443](https://github.com/harttle/liquidjs/issues/443) ([50253a9](https://github.com/harttle/liquidjs/commit/50253a98caf5356d3c33e148be66f34fbe75a204)) -* date filters from Jekyll ([4955e75](https://github.com/harttle/liquidjs/commit/4955e75be7f38a3fd15e71f2c192cff6f0d6e2d5)) -* escape filters from Jekyll, [#443](https://github.com/harttle/liquidjs/issues/443) ([b12eb8a](https://github.com/harttle/liquidjs/commit/b12eb8ab4b58b002459725b6c0ed00159cdc15e6)) -* jsonify, inspect, to_integer, normalize_whitespace filters ([842b45c](https://github.com/harttle/liquidjs/commit/842b45c96a46290a1e1ba43fc5cc7a465f4ba9de)) -* slugify filter from Jekyll, [#443](https://github.com/harttle/liquidjs/issues/443) ([47ddc11](https://github.com/harttle/liquidjs/commit/47ddc1193b84bbdeb8d48457bb5aead24d5aff77)) - -# [10.12.0](https://github.com/harttle/liquidjs/compare/v10.11.1...v10.12.0) (2024-04-28) - - -### Bug Fixes - -* case/when array equality, [#673](https://github.com/harttle/liquidjs/issues/673) ([2b63035](https://github.com/harttle/liquidjs/commit/2b630353c478368cb36dbfcb38961b25bf48249e)) - - -### Features - -* introduce where_exp filter from Jekyll ([8c7cef9](https://github.com/harttle/liquidjs/commit/8c7cef9f95cda765164ada8d58af7d402b3d3143)) - -## [10.11.1](https://github.com/harttle/liquidjs/compare/v10.11.0...v10.11.1) (2024-04-21) - - -### Bug Fixes - -* allow %Z for TimezoneDate, update docs accordingly [#684](https://github.com/harttle/liquidjs/issues/684) ([e09657c](https://github.com/harttle/liquidjs/commit/e09657c52b5e9920256d73f99455e2e81cadf065)) -* Allow `lenientIf` for multiple operands (issue [#682](https://github.com/harttle/liquidjs/issues/682)) ([#683](https://github.com/harttle/liquidjs/issues/683)) ([490ff43](https://github.com/harttle/liquidjs/commit/490ff4309cc231a25be23df5374a5d032aac144e)) - -# [10.11.0](https://github.com/harttle/liquidjs/compare/v10.10.2...v10.11.0) (2024-04-14) - - -### Features - -* group_by/group_by_exp/find/find_exp from Jekyll, [#443](https://github.com/harttle/liquidjs/issues/443) ([2b713b7](https://github.com/harttle/liquidjs/commit/2b713b721d1f355309a70ebb5846169c6c03c523)) -* pop/shift/unshift filters from Jekyll ([258780e](https://github.com/harttle/liquidjs/commit/258780e9a87ce87534a6bb4336725cb1d38a2998)) - -## [10.10.2](https://github.com/harttle/liquidjs/compare/v10.10.1...v10.10.2) (2024-03-21) - - -### Bug Fixes - -* contains regression ([#677](https://github.com/harttle/liquidjs/issues/677)) ([05223c4](https://github.com/harttle/liquidjs/commit/05223c4378f9474f4e658af36cb8272e161d681f)), closes [#675](https://github.com/harttle/liquidjs/issues/675) - -## [10.10.1](https://github.com/harttle/liquidjs/compare/v10.10.0...v10.10.1) (2024-02-18) - - -### Bug Fixes - -* in conditionals, don't render anything after an else branch ([#671](https://github.com/harttle/liquidjs/issues/671)) ([f816955](https://github.com/harttle/liquidjs/commit/f81695570491ede77975de2c26a07612a2d62c28)) -* Rely on equal for computing contains ([#668](https://github.com/harttle/liquidjs/issues/668)) ([1937aa1](https://github.com/harttle/liquidjs/commit/1937aa1f1dce01ee6332f39a6e658e85cbe4f30b)) - -# [10.10.0](https://github.com/harttle/liquidjs/compare/v10.9.4...v10.10.0) (2023-12-19) - - -### Features - -* Array sum filter ([#661](https://github.com/harttle/liquidjs/issues/661)) ([629d958](https://github.com/harttle/liquidjs/commit/629d958b86a97ddf2921d2285b7c9ea83430004e)) - -## [10.9.4](https://github.com/harttle/liquidjs/compare/v10.9.3...v10.9.4) (2023-11-04) - - -### Bug Fixes - -* allow unicode to be identifiers, fixes [#655](https://github.com/harttle/liquidjs/issues/655) ([dd7616a](https://github.com/harttle/liquidjs/commit/dd7616acb9a71b77f39d2fa24b6f68a7caef87f1)) - -## [10.9.3](https://github.com/harttle/liquidjs/compare/v10.9.2...v10.9.3) (2023-10-15) - - -### Bug Fixes - -* package version in released files ([67a5b22](https://github.com/harttle/liquidjs/commit/67a5b229ca9ccabb4aee42bbb5c9f03d4076786a)) - -## [10.9.2](https://github.com/harttle/liquidjs/compare/v10.9.1...v10.9.2) (2023-08-28) - - -### Bug Fixes - -* handle windows newlines on `newline_to_br` and `strip_newlines` ([88aa63f](https://github.com/harttle/liquidjs/commit/88aa63fd58b5a5824c031acc6f3e4072bedd262f)) -* sort and where bug when using `strictVariables` ([8af682d](https://github.com/harttle/liquidjs/commit/8af682d2ca68de99bafd4a7055e4912eeb318f57)) - -## [10.9.1](https://github.com/harttle/liquidjs/compare/v10.9.0...v10.9.1) (2023-08-23) - - -### Bug Fixes - -* map filter allow nil results in strict mode, fixes [#647](https://github.com/harttle/liquidjs/issues/647) ([45adbd7](https://github.com/harttle/liquidjs/commit/45adbd7008296a94da04d21a35917f744a0f4109)) - -# [10.9.0](https://github.com/harttle/liquidjs/compare/v10.8.4...v10.9.0) (2023-08-22) - - -### Bug Fixes - -* case should allow multiple values separated by or ([b8e7e2d](https://github.com/harttle/liquidjs/commit/b8e7e2d9467b17ca786e6fb422e9579dd178de76)) -* for throws undefined var with a null value with strictVariables ([dc6a301](https://github.com/harttle/liquidjs/commit/dc6a3013874872ac85f1fbe5184c74631122d851)) -* remove_last was eating an extra character ([fc27313](https://github.com/harttle/liquidjs/commit/fc2731376f8ef59ac7160f97cef1fb5d94f053db)) - - -### Features - -* more flexible squared property read expression, fixes [#643](https://github.com/harttle/liquidjs/issues/643) ([#646](https://github.com/harttle/liquidjs/issues/646)) ([660d9be](https://github.com/harttle/liquidjs/commit/660d9be55f8eac16ca5ac77fd0b38b0d7f94961e)) - -## [10.8.4](https://github.com/harttle/liquidjs/compare/v10.8.3...v10.8.4) (2023-07-07) - - -### Bug Fixes - -* allow quotes in inline comment tag, fixes [#628](https://github.com/harttle/liquidjs/issues/628) ([bf425c3](https://github.com/harttle/liquidjs/commit/bf425c3adb929e68fa234bee8397560a436595bb)) - -## [10.8.3](https://github.com/harttle/liquidjs/compare/v10.8.2...v10.8.3) (2023-06-16) - - -### Bug Fixes - -* strftime getSuffix works for all dates ([0b4e2a9](https://github.com/harttle/liquidjs/commit/0b4e2a99790347bea0ab5f7d651f2330e3054601)) - -## [10.8.2](https://github.com/harttle/liquidjs/compare/v10.8.1...v10.8.2) (2023-06-04) - - -### Bug Fixes - -* sample filter randomness and count=1 case ([fcb930f](https://github.com/harttle/liquidjs/commit/fcb930f0ddf2489fa74cd323f24398d7e9f7717f)) - -## [10.8.1](https://github.com/harttle/liquidjs/compare/v10.8.0...v10.8.1) (2023-06-04) - - -### Bug Fixes - -* incorrect error message for browser UMD bundle ([3a67eb7](https://github.com/harttle/liquidjs/commit/3a67eb7f1cc7e54d2ec94a985eca4c1f147cdd61)) - -# [10.8.0](https://github.com/harttle/liquidjs/compare/v10.7.1...v10.8.0) (2023-06-03) - - -### Bug Fixes - -* proper error message for filter syntax error, [#610](https://github.com/harttle/liquidjs/issues/610) ([0480d33](https://github.com/harttle/liquidjs/commit/0480d3317d0e46519ad2adf4ac43f53cddf467c6)) -* sed invocations to work out of the box on macOS ([#615](https://github.com/harttle/liquidjs/issues/615)) ([87d4cc7](https://github.com/harttle/liquidjs/commit/87d4cc7e14ece14161285a740be63afc8a88b63c)) - - -### Features - -* Add support for the Jekyll sample filter ([#612](https://github.com/harttle/liquidjs/issues/612)) ([ba8b842](https://github.com/harttle/liquidjs/commit/ba8b84245266589e43c0e70d99e12b981d349809)) -* Add support for the Jekyll push filter ([#611](https://github.com/harttle/liquidjs/issues/611)) -* introduce a matrix with latest Ubuntu and macOS to test the build on macOS as well ([82ba548](https://github.com/harttle/liquidjs/commit/82ba54845f4cd4e1e7660c1557e3cfaa22d68924)), closes [#615](https://github.com/harttle/liquidjs/issues/615) -* precise line/col for tokenization Error, [#613](https://github.com/harttle/liquidjs/issues/613) ([e347e60](https://github.com/harttle/liquidjs/commit/e347e603d76c039cec191d417deab34e7ef1f9a7)) - -## [10.7.1](https://github.com/harttle/liquidjs/compare/v10.7.0...v10.7.1) (2023-04-24) - - -### Bug Fixes - -* incorrect timezone correction for DST dates, fixes [#604](https://github.com/harttle/liquidjs/issues/604) ([33b3c01](https://github.com/harttle/liquidjs/commit/33b3c010af0cd17a303621331feab0119ca840ce)) -* timezoneOffset ignored in date when preserveTimezones is enabled, fixes [#605](https://github.com/harttle/liquidjs/issues/605) ([21ee27b](https://github.com/harttle/liquidjs/commit/21ee27b57503f9d57f228973e1699972484e6089)) - -# [10.7.0](https://github.com/harttle/liquidjs/compare/v10.6.2...v10.7.0) (2023-03-21) - - -### Bug Fixes - -* update remove.md ([#601](https://github.com/harttle/liquidjs/issues/601)) ([1bddd60](https://github.com/harttle/liquidjs/commit/1bddd60b0191032d324526292027bc7fcd190dc1)) - - -### Features - -* JSON format by `space` in `json` filter ([7b87ea8](https://github.com/harttle/liquidjs/commit/7b87ea82d3d63420e548743c5a84a073f0cdad22)) - -## [10.6.2](https://github.com/harttle/liquidjs/compare/v10.6.1...v10.6.2) (2023-03-19) - - -### Bug Fixes - -* sample FS in render-file.md ([#594](https://github.com/harttle/liquidjs/issues/594)) ([4542ddc](https://github.com/harttle/liquidjs/commit/4542ddcfc3d5e245112a119bf22f0e00cb925791)) - -## [10.6.1](https://github.com/harttle/liquidjs/compare/v10.6.0...v10.6.1) (2023-03-02) - - -### Bug Fixes - -* [expression] apply value equal for arrays, [#589](https://github.com/harttle/liquidjs/issues/589) ([9c0dc5f](https://github.com/harttle/liquidjs/commit/9c0dc5fa39a31d477a5c5a2c5212034174bf0516)) -* strip_html for multi line -``` - -Or render directly from CLI using npx: - -```bash -npx liquidjs --template 'Hello, {{ name }}!' --context '{"name": "Snake"}' -``` - -For more details, refer to the [Setup Guide][setup]. - -## Who's Using LiquidJS? - -- [Eleventy](https://www.11ty.dev/): Eleventy, a simpler static site generator. -- [Github Docs](https://github.com/github/docs): The open-source repo for docs.github.com. -- [Opensense](https://www.opensense.com/): The smarter way to send email. -- [Directus](https://docs.directus.io/): an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database. -- [Semgrep](https://github.com/returntocorp/semgrep): Lightweight static analysis for many languages. -- [Rock](https://www.rockrms.com/): An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one. -- [Mitosis](https://github.com/BuilderIO/mitosis): Write components once, run everywhere. Compiles to React, Vue, Qwik, Solid, Angular, Svelte, and more. -- [Pattern Lab](https://patternlab.io/): a frontend workshop environment that helps you build, view, test, and showcase your design system's UI components. -- [Builder.io](https://www.builder.io/m/developers): 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](https://learn.microsoft.com/en-us/power-pages/introduction): a secure, enterprise-grade, low-code software as a service (SaaS) platform for creating, hosting, and administering modern external-facing business websites. -- [Azure API Management developer portal](https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-developer-portal): an automatically generated, fully customizable website with the documentation of your APIs. -- [WISMOlabs](https://wismolabs.com/): 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. - -Feel free to create a PR or contact me to add your use case into this list! - -## Financial Support - -If you personally love LiquidJS or it's benefiting your business, please consider financially support us via [GitHub Sponsors](https://github.com/sponsors/harttle). Special thanks to our sponsors! - - -
![]() Opensense |
- Eleventy |
- Peter deHaan |
- ![]() Touchless |
- ![]() Dropkiq |
- ![]() Dailycontributors |
- Serkan Holat |
-
amit777 |
- ![]() Khaled Salem |
- Sentry |
- Checkout Blocks |
- Customer IO |
- Emmanuel Cartelli |
- Microsoft |
-
![]() PakStyle.pk |
- Syntax Podcast |
- ![]() Cartelli Emmanuel |
- ![]() EscortA.com |
- ![]() Chudovo |
-
user passed in scope
+{% increment %}
, {% decrement %}
changes this scope,
+whereas {% capture %}
, {% assign %}
only hide this scope
global scope used as fallback for missing variables
+The normalized liquid options object
+Throw when accessing undefined variable?
+Optional
scope: object | ContextOptional
sync: booleanOptional
lookupType: LookupTypeOptional
currentFile: stringOptional
scope: object | ContextOptional
scope: object | ContextReturn an array of all variables including their properties/paths.
+Return an array of all variables including their properties/paths.
+Return an array of all expected context variables including their properties/paths.
+Return an array of all expected context variables including their properties/paths.
+Return an array of all expected context variables, each as an array of properties/segments.
+Return an array of all expected context variables, each as an array of properties/segments.
+Return an array of all expected context variables without their properties.
+Return an array of all expected context variables without their properties.
+Optional
filename: stringOptional
filename: stringOptional
scope: object | ContextOptional
renderOptions: RenderOptionsOptional
scope: object | ContextOptional
renderOptions: RenderOptionsOptional
lookupType: LookupTypeOptional
lookupType: LookupTypeOptional
scope: objectOptional
renderOptions: RenderOptionsOptional
ctx: object | ContextOptional
renderFileOptions: RenderFileOptionsOptional
ctx: object | ContextOptional
renderFileOptions: RenderFileOptionsOptional
scope: objectOptional
renderOptions: RenderOptionsOptional
scope: objectOptional
renderOptions: RenderOptionsOptional
scope: objectReturn an array of all variables, each as an array of properties/segments.
+Return an array of all variables, each as an array of properties/segments.
+Return an array of all variables without their properties.
+Return an array of all variables without their properties.
+Abstract
Optional
originalOptional
stackStatic
Optional
prepareOptional override for formatting stack traces
+Static
stackProtected
updateStatic
captureStatic
isOptional
originalOptional
stackStatic
Optional
prepareOptional override for formatting stack traces
+Static
stackProtected
updateStatic
captureStatic
isOptional
originalOptional
stackStatic
Optional
prepareOptional override for formatting stack traces
+Static
stackProtected
updateStatic
captureStatic
isProtected
tokenizerOptional
file: stringAbstract
Optional
originalOptional
stackStatic
Optional
prepareOptional override for formatting stack traces
+Static
stackProtected
updateStatic
captureStatic
isOptional
originalOptional
stackStatic
Optional
prepareOptional override for formatting stack traces
+Static
stackProtected
updateStatic
captureStatic
isA variable's segments and location, which can be coerced to a string.
+Return this variable's segments as an array, possibly with nested arrays for nested paths.
+Provide parent access in child block by +{{ block.super }}
+Abstract
Optional
file: stringOptional
file: stringvalue expression with optional filters +e.g. +{% assign foo="bar" | append: "coo" %}
+Optional
file: stringOptional
value: ValueTokenOptional
file: stringOptional
file: stringLiquidTagToken is different from TagToken by not having delimiters {%
or %}
Optional
file: stringOptional
file: stringOptional
sync: booleanOptional
currentFile: stringOptional
file: stringOptional
file: stringOptional
file: stringOptional
file: stringOptional
file: stringOptional
file: stringAbstract
Statically analyze a template and report variable usage.
+Statically analyze a template and report variable usage.
+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.
+Basically there're two types of Liquid syntax: tags enclosed by {% %}
and outputs enclosed by {{ }}
. A Liquid template looks like:
{% if username %}
+ {{ username | append: ", welcome to LiquidJS!" | capitalize }}
+{% endif %}
+
+
+A live demo is also available and here's a quick tutorial for Liquid syntax.
+Install from npm in Node.js:
+npm install liquidjs
+
+
+Or use the UMD bundle from jsDelivr:
+<script src="https://cdn.jsdelivr.net/npm/liquidjs/dist/liquid.browser.min.js"></script>
+
+
+Or render directly from CLI using npx:
+npx liquidjs --template 'Hello, {{ name }}!' --context '{"name": "Snake"}'
+
+
+For more details, refer to the Setup Guide.
+Feel free to create a PR or contact me to add your use case into this list!
+If you personally love LiquidJS or it's benefiting your business, please consider financially support us via GitHub Sponsors. Special thanks to our sponsors!
+ +![]() Opensense |
+ Eleventy |
+ Peter deHaan |
+ ![]() Touchless |
+ ![]() Dropkiq |
+ ![]() Dailycontributors |
+ Serkan Holat |
+
amit777 |
+ ![]() Khaled Salem |
+ Sentry |
+ Checkout Blocks |
+ Customer IO |
+ Emmanuel Cartelli |
+ Microsoft |
+
![]() PakStyle.pk |
+ Syntax Podcast |
+ ![]() Cartelli Emmanuel |
+ ![]() EscortA.com |
+ ![]() Chudovo |
+
Want to contribute? see Contribution Guidelines. Thanks goes to these wonderful people:
+ + + +Optional
containscheck if file is contained in root
, always return true
by default. Warning: not setting this could expose path traversal vulnerabilities.
Optional
dirnamerequired for relative path resolving
+check if a file exists asynchronously
+check if a file exists synchronously
+Optional
fallbackfallback file for lookup failure
+read a file asynchronously
+read a file synchronously
+resolve a file against directory, for given ext
option
Optional
sepdefaults to "/"
+Optional
cacheWhether or not to cache resolved templates. Defaults to false
.
Optional
catchCatch all errors instead of exit upon one. Please note that render errors won't be reached when parse fails.
+Optional
dateDefault date format to use if the date filter doesn't include a format. Defaults to %A, %B %-e, %Y at %-l:%M %P %z
.
Optional
dynamicIf set, treat the filepath
parameter in {%include filepath %}
and {%layout filepath%}
as a variable, otherwise as a literal value. Defaults to true
.
Optional
extnameAdd a extname (if filepath doesn't include one) before template file lookup. Eg: setting to ".html"
will allow including file by basename. Defaults to ""
.
Optional
fsfs
is used to override the default file-system module with a custom implementation.
Optional
globalsthe global scope passed down to all partial and layout templates, i.e. templates included by include
, layout
and render
tags.
Optional
greedyWhether trim*Left
/trim*Right
is greedy. When set to true
, all consecutive blank characters including \n
will be trimmed regardless of line breaks. Defaults to true
.
Optional
jekyllUse jekyll style include, pass parameters to include
variable of current scope. Defaults to false
.
Optional
jekyllUse jekyll style where filter, enables array item match. Defaults to false
.
Optional
jsUse JavaScript Truthiness. Defaults to false
.
Optional
keepWhether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to false
.
Optional
keykeyValue separator
+Optional
layoutsA directory or an array of directories from where to resolve layout templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to root
Optional
lenientModifies the behavior of strictVariables
. If set, a single undefined variable will not cause an exception in the context of the if
/elsif
/unless
tag and the default
filter. Instead, it will evaluate to false
and null
, respectively. Irrelevant if strictVariables
is not set. Defaults to false
. *
Optional
localeDefault locale, will be used by date filter. Defaults to system locale.
+Optional
memoryFor DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue.
+Optional
operatorsAn object of operators for conditional statements. Defaults to the regular Liquid operators.
+Optional
orderedRespect parameter order when using filters like "for ... reversed limit", Defaults to false
.
Optional
outputThe left delimiter for liquid outputs. *
+Optional
outputThe right delimiter for liquid outputs. *
+Optional
outputDefault escape filter applied to output values, when set, you'll have to add | raw
for values don't need to be escaped. Defaults to undefined
.
Optional
ownHide scope variables from prototypes, useful when you're passing a not sanitized object into LiquidJS or need to hide prototypes from templates.
+Optional
parseFor DoS handling, limit total length of templates parsed in one parse()
call. A typical PC can handle 1e8 (100M) characters without issues.
Optional
partialsA directory or an array of directories from where to resolve included templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to root
Optional
preserveWhether input strings to date filter preserve the given timezone *
+Optional
relativeAllow refer to layouts/partials by relative pathname. To avoid arbitrary filesystem read, paths been referenced also need to be within corresponding root, partials, layouts. Defaults to true
.
Optional
renderFor DoS handling, limit total time (in ms) for each render()
call.
Optional
rootA directory or an array of directories from where to resolve layout and include templates, and the filename passed to .renderFile()
. If it's an array, the files are looked up in the order they occur in the array. Defaults to ["."]
Optional
strictWhether or not to assert filter existence. If set to false
, undefined filters will be skipped. Otherwise, undefined filters will cause an exception. Defaults to false
.
Optional
strictWhether or not to assert variable existence. If set to false
, undefined variables will be rendered as empty string. Otherwise, undefined variables will cause an exception. Defaults to false
.
Optional
tagThe left delimiter for liquid tags. *
+Optional
tagThe right delimiter for liquid tags. *
+Optional
templatesRender from in-memory templates
mapping instead of file system. File system related options like fs
, 'root', and relativeReference
will be ignored when templates
is specified.
Optional
timezoneJavaScript timezone name or timezoneOffset for date
filter, default to local time. That means if you're in Australia (UTC+10), it'll default to -600
or Australia/Lindeman
Optional
trimSimilar to trimOutputRight
, whereas the \n
is exclusive. Defaults to false
. See Whitespace Control for details.
Optional
trimStrip blank characters (including
, \t
, and \r
) from the right of values ({{ }}
) until \n
(inclusive). Defaults to false
.
Optional
trimSimilar to trimTagRight
, whereas the \n
is exclusive. Defaults to false
. See Whitespace Control for details.
Optional
trimStrip blank characters (including
, \t
, and \r
) from the right of tags ({% %}
) until \n
(inclusive). Defaults to false
.
Scope information used when analyzing partial templates.
+If true
, names in scope
will be added to a new, isolated scope before
+analyzing any child templates, without access to the parent template's scope.
The name of the partial template. We need this to make sure we only analyze +each template once.
+A list of names that will be in scope for the child template.
+If an item is a [string, Argument] tuple, the string is considered an alias +for the argument.
+The result of calling analyze()
or analyzeSync()
.
Variables that are not in scope. These could be a "global" variables that are +expected to be provided by the application developer, or possible mistakes +from the template author.
+If a variable is referenced before and after assignment, you should expect
+that variable to be included in globals
, variables
and locals
, each with
+a different location.
Template variables that are added to the template local scope using tags like
+assign
, capture
or increment
.
All variables, whether they are in scope or not. Including references to names
+such as forloop
from the for
tag.
Optional
argumentsOptional
blockOptional
childrenOptional
localOptional
partialRest
...args: [] | [undefined]Optional
returnOptional
value: anyOptional
throwOptional
e: anyRest
...args: [] | [TNext]Optional
returnOptional
value: TReturn | PromiseLike<TReturn>Optional
throwOptional
e: anyReadonly
BYTES_The size in bytes of each element in the array.
+Readonly
[toReadonly
bufferThe ArrayBuffer instance referenced by the array.
+Readonly
byteThe length in bytes of the array.
+Readonly
byteThe offset in bytes of the array.
+Readonly
lengthThe length of the array.
+Compares buf
with target
and returns a number indicating whether buf
comes before, after, or is the same as target
in sort order.
+Comparison is based on the actual sequence of bytes in each Buffer
.
0
is returned if target
is the same as buf
1
is returned if target
should come beforebuf
when sorted.-1
is returned if target
should come afterbuf
when sorted.import { Buffer } from 'node:buffer';
const buf1 = Buffer.from('ABC');
const buf2 = Buffer.from('BCD');
const buf3 = Buffer.from('ABCD');
console.log(buf1.compare(buf1));
// Prints: 0
console.log(buf1.compare(buf2));
// Prints: -1
console.log(buf1.compare(buf3));
// Prints: -1
console.log(buf2.compare(buf1));
// Prints: 1
console.log(buf2.compare(buf3));
// Prints: 1
console.log([buf1, buf2, buf3].sort(Buffer.compare));
// Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
// (This result is equal to: [buf1, buf3, buf2].)
+
+
+The optional targetStart
, targetEnd
, sourceStart
, and sourceEnd
arguments can be used to limit the comparison to specific ranges within target
and buf
respectively.
import { Buffer } from 'node:buffer';
const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
console.log(buf1.compare(buf2, 5, 9, 0, 4));
// Prints: 0
console.log(buf1.compare(buf2, 0, 6, 4));
// Prints: -1
console.log(buf1.compare(buf2, 5, 6, 5));
// Prints: 1
+
+
+ERR_OUT_OF_RANGE
is thrown if targetStart < 0
, sourceStart < 0
, targetEnd > target.byteLength
, or sourceEnd > source.byteLength
.
A Buffer
or Uint8Array with which to compare buf
.
Optional
targetStart: numberThe offset within target
at which to begin comparison.
Optional
targetEnd: numberThe offset within target
at which to end comparison (not inclusive).
Optional
sourceStart: numberThe offset within buf
at which to begin comparison.
Optional
sourceEnd: numberThe offset within buf
at which to end comparison (not inclusive).
Copies data from a region of buf
to a region in target
, even if the target
memory region overlaps with buf
.
TypedArray.prototype.set()
performs the same operation, and is available
+for all TypedArrays, including Node.js Buffer
s, although it takes
+different function arguments.
import { Buffer } from 'node:buffer';
// Create two `Buffer` instances.
const buf1 = Buffer.allocUnsafe(26);
const buf2 = Buffer.allocUnsafe(26).fill('!');
for (let i = 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);
console.log(buf2.toString('ascii', 0, 25));
// Prints: !!!!!!!!qrst!!!!!!!!!!!!!
+
+
+import { Buffer } from 'node:buffer';
// Create a `Buffer` and copy data from one region to an overlapping region
// within the same `Buffer`.
const buf = Buffer.allocUnsafe(26);
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'.
buf[i] = i + 97;
}
buf.copy(buf, 0, 4, 10);
console.log(buf.toString());
// Prints: efghijghijklmnopqrstuvwxyz
+
+
+A Buffer
or Uint8Array to copy into.
Optional
targetStart: numberThe offset within target
at which to begin writing.
Optional
sourceStart: numberThe offset within buf
from which to begin copying.
Optional
sourceEnd: numberThe offset within buf
at which to stop copying (not inclusive).
The number of bytes copied.
+Returns the this object after copying a section of the array identified by start and end +to the same array starting at position target
+If target is negative, it is treated as length+target where length is the +length of the array.
+If start is negative, it is treated as length+start. If end is negative, it +is treated as length+end.
+Optional
end: numberIf not specified, length of the this object is used as its default value.
+Returns an array of key, value pairs for every entry in the array
+Returns true
if both buf
and otherBuffer
have exactly the same bytes,false
otherwise. Equivalent to buf.compare(otherBuffer) === 0
.
import { Buffer } from 'node:buffer';
const buf1 = Buffer.from('ABC');
const buf2 = Buffer.from('414243', 'hex');
const buf3 = Buffer.from('ABCD');
console.log(buf1.equals(buf2));
// Prints: true
console.log(buf1.equals(buf3));
// Prints: false
+
+
+A Buffer
or Uint8Array with which to compare buf
.
Determines whether all the members of an array satisfy the specified test.
+A function that accepts up to three arguments. The every method calls +the predicate function for each element in the array until the predicate returns a value +which is coercible to the Boolean value false, or until the end of the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. +If thisArg is omitted, undefined is used as the this value.
+Fills buf
with the specified value
. If the offset
and end
are not given,
+the entire buf
will be filled:
import { Buffer } from 'node:buffer';
// Fill a `Buffer` with the ASCII character 'h'.
const b = Buffer.allocUnsafe(50).fill('h');
console.log(b.toString());
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
// Fill a buffer with empty string
const c = Buffer.allocUnsafe(5).fill('');
console.log(c.fill(''));
// Prints: <Buffer 00 00 00 00 00>
+
+
+value
is coerced to a uint32
value if it is not a string, Buffer
, or
+integer. If the resulting integer is greater than 255
(decimal), buf
will be
+filled with 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.
console.log(Buffer.allocUnsafe(5).fill('\u0222'));
// Prints: <Buffer c8 a2 c8 a2 c8>
+
+
+If value
contains invalid characters, it is truncated; if no valid
+fill data remains, an exception is thrown:
import { Buffer } from 'node:buffer';
const buf = 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.
+
+
+The value with which to fill buf
. Empty value (string, Uint8Array, Buffer) is coerced to 0
.
Optional
offset: numberNumber of bytes to skip before starting to fill buf
.
Optional
end: numberWhere to stop filling buf
(not inclusive).
Optional
encoding: BufferEncodingThe encoding for value
if value
is a string.
A reference to buf
.
Returns the elements of an array that meet the condition specified in a callback function.
+A function that accepts up to three arguments. The filter method calls +the predicate function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. +If thisArg is omitted, undefined is used as the this value.
+Returns the value of the first element in the array where predicate is true, and undefined +otherwise.
+find calls predicate once for each element of the array, in ascending +order, until it finds one where predicate returns true. If such an element is found, find +immediately returns that element value. Otherwise, find returns undefined.
+Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of +predicate. If it is not provided, undefined is used instead.
+Returns the index of the first element in the array where predicate is true, and -1 +otherwise.
+find calls predicate once for each element of the array, in ascending +order, until it finds one where predicate returns true. If such an element is found, +findIndex immediately returns that element index. Otherwise, findIndex returns -1.
+Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of +predicate. If it is not provided, undefined is used instead.
+Performs the specified action for each element in an array.
+A function that accepts up to three arguments. forEach calls the +callbackfn function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. +If thisArg is omitted, undefined is used as the this value.
+Equivalent to buf.indexOf() !== -1
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from('this is a buffer');
console.log(buf.includes('this'));
// Prints: true
console.log(buf.includes('is'));
// Prints: true
console.log(buf.includes(Buffer.from('a buffer')));
// Prints: true
console.log(buf.includes(97));
// Prints: true (97 is the decimal ASCII value for 'a')
console.log(buf.includes(Buffer.from('a buffer example')));
// Prints: false
console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false
+
+
+What to search for.
+Optional
byteOffset: numberWhere to begin searching in buf
. If negative, then offset is calculated from the end of buf
.
Optional
encoding: BufferEncodingIf value
is a string, this is its encoding.
true
if value
was found in buf
, false
otherwise.
If value
is:
value
is interpreted according to the character encoding in encoding
.Buffer
or Uint8Array
, value
will be used in its entirety.
+To compare a partial Buffer
, use buf.subarray
.value
will be interpreted as an unsigned 8-bit integer
+value between 0
and 255
.import { Buffer } from 'node:buffer';
const buf = Buffer.from('this is a buffer');
console.log(buf.indexOf('this'));
// Prints: 0
console.log(buf.indexOf('is'));
// Prints: 2
console.log(buf.indexOf(Buffer.from('a buffer')));
// Prints: 8
console.log(buf.indexOf(97));
// Prints: 8 (97 is the decimal ASCII value for 'a')
console.log(buf.indexOf(Buffer.from('a buffer example')));
// Prints: -1
console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
// Prints: 8
const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
// Prints: 4
console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
// Prints: 6
+
+
+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,
+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';
const b = 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
+than buf.length
, byteOffset
will be returned. If value
is empty andbyteOffset
is at least buf.length
, buf.length
will be returned.
What to search for.
+Optional
byteOffset: numberWhere to begin searching in buf
. If negative, then offset is calculated from the end of buf
.
Optional
encoding: BufferEncodingIf value
is a string, this is the encoding used to determine the binary representation of the string that will be searched for in buf
.
The index of the first occurrence of value
in buf
, or -1
if buf
does not contain value
.
Adds all the elements of an array separated by the specified separator string.
+Optional
separator: stringA string used to separate one element of an array from the next in the +resulting String. If omitted, the array elements are separated with a comma.
+Returns an list of keys in the array
+Identical to buf.indexOf()
, except the last occurrence of value
is found
+rather than the first occurrence.
import { Buffer } from 'node:buffer';
const buf = Buffer.from('this buffer is a buffer');
console.log(buf.lastIndexOf('this'));
// Prints: 0
console.log(buf.lastIndexOf('buffer'));
// Prints: 17
console.log(buf.lastIndexOf(Buffer.from('buffer')));
// Prints: 17
console.log(buf.lastIndexOf(97));
// Prints: 15 (97 is the decimal ASCII value for 'a')
console.log(buf.lastIndexOf(Buffer.from('yolo')));
// Prints: -1
console.log(buf.lastIndexOf('buffer', 5));
// Prints: 5
console.log(buf.lastIndexOf('buffer', 4));
// Prints: -1
const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
// Prints: 6
console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
// Prints: 4
+
+
+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,
+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';
const b = 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.
What to search for.
+Optional
byteOffset: numberWhere to begin searching in buf
. If negative, then offset is calculated from the end of buf
.
Optional
encoding: BufferEncodingIf value
is a string, this is the encoding used to determine the binary representation of the string that will be searched for in buf
.
The index of the last occurrence of value
in buf
, or -1
if buf
does not contain value
.
Calls a defined callback function on each element of an array, and returns an array that +contains the results.
+A function that accepts up to three arguments. The map method calls the +callbackfn function one time for each element in the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. +If thisArg is omitted, undefined is used as the this value.
+Reads a signed, big-endian 64-bit integer from buf
at the specified offset
.
Integers read from a Buffer
are interpreted as two's complement signed
+values.
Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8
.
Reads a signed, little-endian 64-bit integer from buf
at the specifiedoffset
.
Integers read from a Buffer
are interpreted as two's complement signed
+values.
Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8
.
Reads an unsigned, big-endian 64-bit integer from buf
at the specifiedoffset
.
This function is also available under the readBigUint64BE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
console.log(buf.readBigUInt64BE(0));
// Prints: 4294967295n
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8
.
Reads an unsigned, little-endian 64-bit integer from buf
at the specifiedoffset
.
This function is also available under the readBigUint64LE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
console.log(buf.readBigUInt64LE(0));
// Prints: 18446744069414584320n
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8
.
Reads a 64-bit, big-endian double from buf
at the specified offset
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleBE(0));
// Prints: 8.20788039913184e-304
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8
.
Reads a 64-bit, little-endian double from buf
at the specified offset
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleLE(0));
// Prints: 5.447603722011605e-270
console.log(buf.readDoubleLE(1));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8
.
Reads a 32-bit, big-endian float from buf
at the specified offset
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([1, 2, 3, 4]);
console.log(buf.readFloatBE(0));
// Prints: 2.387939260590663e-38
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
.
Reads a 32-bit, little-endian float from buf
at the specified offset
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([1, 2, 3, 4]);
console.log(buf.readFloatLE(0));
// Prints: 1.539989614439558e-36
console.log(buf.readFloatLE(1));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
.
Reads a signed, big-endian 16-bit integer from buf
at the specified offset
.
Integers read from a Buffer
are interpreted as two's complement signed values.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0, 5]);
console.log(buf.readInt16BE(0));
// Prints: 5
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
.
Reads a signed, little-endian 16-bit integer from buf
at the specifiedoffset
.
Integers read from a Buffer
are interpreted as two's complement signed values.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0, 5]);
console.log(buf.readInt16LE(0));
// Prints: 1280
console.log(buf.readInt16LE(1));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
.
Reads a signed, big-endian 32-bit integer from buf
at the specified offset
.
Integers read from a Buffer
are interpreted as two's complement signed values.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0, 0, 0, 5]);
console.log(buf.readInt32BE(0));
// Prints: 5
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
.
Reads a signed, little-endian 32-bit integer from buf
at the specifiedoffset
.
Integers read from a Buffer
are interpreted as two's complement signed values.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0, 0, 0, 5]);
console.log(buf.readInt32LE(0));
// Prints: 83886080
console.log(buf.readInt32LE(1));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
.
Reads a signed 8-bit integer from buf
at the specified offset
.
Integers read from a Buffer
are interpreted as two's complement signed values.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([-1, 5]);
console.log(buf.readInt8(0));
// Prints: -1
console.log(buf.readInt8(1));
// Prints: 5
console.log(buf.readInt8(2));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1
.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readIntBE(0, 6).toString(16));
// Prints: 1234567890ab
console.log(buf.readIntBE(1, 6).toString(16));
// Throws ERR_OUT_OF_RANGE.
console.log(buf.readIntBE(1, 0).toString(16));
// Throws ERR_OUT_OF_RANGE.
+
+
+Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to read. Must satisfy 0 < byteLength <= 6
.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readIntLE(0, 6).toString(16));
// Prints: -546f87a9cbee
+
+
+Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to read. Must satisfy 0 < byteLength <= 6
.
Reads an unsigned, big-endian 16-bit integer from buf
at the specifiedoffset
.
This function is also available under the readUint16BE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56]);
console.log(buf.readUInt16BE(0).toString(16));
// Prints: 1234
console.log(buf.readUInt16BE(1).toString(16));
// Prints: 3456
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
.
Reads an unsigned, little-endian 16-bit integer from buf
at the specified offset
.
This function is also available under the readUint16LE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56]);
console.log(buf.readUInt16LE(0).toString(16));
// Prints: 3412
console.log(buf.readUInt16LE(1).toString(16));
// Prints: 5634
console.log(buf.readUInt16LE(2).toString(16));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
.
Reads an unsigned, big-endian 32-bit integer from buf
at the specifiedoffset
.
This function is also available under the readUint32BE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
console.log(buf.readUInt32BE(0).toString(16));
// Prints: 12345678
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
.
Reads an unsigned, little-endian 32-bit integer from buf
at the specifiedoffset
.
This function is also available under the readUint32LE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
console.log(buf.readUInt32LE(0).toString(16));
// Prints: 78563412
console.log(buf.readUInt32LE(1).toString(16));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
.
Reads an unsigned 8-bit integer from buf
at the specified offset
.
This function is also available under the readUint8
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([1, -2]);
console.log(buf.readUInt8(0));
// Prints: 1
console.log(buf.readUInt8(1));
// Prints: 254
console.log(buf.readUInt8(2));
// Throws ERR_OUT_OF_RANGE.
+
+
+Optional
offset: numberNumber of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1
.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readUIntBE(0, 6).toString(16));
// Prints: 1234567890ab
console.log(buf.readUIntBE(1, 6).toString(16));
// Throws ERR_OUT_OF_RANGE.
+
+
+Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to read. Must satisfy 0 < byteLength <= 6
.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readUIntLE(0, 6).toString(16));
// Prints: ab9078563412
+
+
+Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to read. Must satisfy 0 < byteLength <= 6
.
Calls the specified callback function for all the elements in an array. The return value of +the callback function is the accumulated result, and is provided as an argument in the next +call to the callback function.
+A function that accepts up to four arguments. The reduce method calls the +callbackfn function one time for each element in the array.
+Calls the specified callback function for all the elements in an array. The return value of +the callback function is the accumulated result, and is provided as an argument in the next +call to the callback function.
+A function that accepts up to four arguments. The reduce method calls the +callbackfn function one time for each element in the array.
+If initialValue is specified, it is used as the initial value to start +the accumulation. The first call to the callbackfn function provides this value as an argument +instead of an array value.
+Calls the specified callback function for all the elements in an array, in descending order. +The return value of the callback function is the accumulated result, and is provided as an +argument in the next call to the callback function.
+A function that accepts up to four arguments. The reduceRight method calls +the callbackfn function one time for each element in the array.
+Calls the specified callback function for all the elements in an array, in descending order. +The return value of the callback function is the accumulated result, and is provided as an +argument in the next call to the callback function.
+A function that accepts up to four arguments. The reduceRight method calls +the callbackfn function one time for each element in the array.
+If initialValue is specified, it is used as the initial value to start +the accumulation. The first call to the callbackfn function provides this value as an argument +instead of an array value.
+Sets a value or an array of values.
+A typed or untyped array of values to set.
+Optional
offset: numberThe index in the current array at which the values are to be written.
+Returns a new Buffer
that references the same memory as the original, but
+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()
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from('buffer');
const copiedBuf = Uint8Array.prototype.slice.call(buf);
copiedBuf[0]++;
console.log(copiedBuf.toString());
// Prints: cuffer
console.log(buf.toString());
// Prints: buffer
// With buf.slice(), the original buffer is modified.
const notReallyCopiedBuf = buf.slice();
notReallyCopiedBuf[0]++;
console.log(notReallyCopiedBuf.toString());
// Prints: cuffer
console.log(buf.toString());
// Also prints: cuffer (!)
+
+
+Optional
start: numberWhere the new Buffer
will start.
Optional
end: numberWhere the new Buffer
will end (not inclusive).
Determines whether the specified callback function returns true for any element of an array.
+A function that accepts up to three arguments. The some method calls +the predicate function for each element in the array until the predicate returns a value +which is coercible to the Boolean value true, or until the end of the array.
+Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. +If thisArg is omitted, undefined is used as the this value.
+Sorts an array.
+Optional
compareFn: ((a: number, b: number) => number)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.
+[11,2,22,1].sort((a, b) => a - b)
+
+
+Returns a new Buffer
that references the same memory as the original, but
+offset and cropped by the start
and end
indices.
Specifying end
greater than buf.length
will return the same result as
+that of end
equal to buf.length
.
This method is inherited from TypedArray.prototype.subarray()
.
Modifying the new Buffer
slice will modify the memory in the original Buffer
because the allocated memory of the two objects overlap.
import { Buffer } from 'node:buffer';
// Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
// from the original `Buffer`.
const buf1 = Buffer.allocUnsafe(26);
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'.
buf1[i] = i + 97;
}
const buf2 = buf1.subarray(0, 3);
console.log(buf2.toString('ascii', 0, buf2.length));
// Prints: abc
buf1[0] = 33;
console.log(buf2.toString('ascii', 0, buf2.length));
// Prints: !bc
+
+
+Specifying negative indexes causes the slice to be generated relative to the
+end of buf
rather than the beginning.
import { Buffer } from 'node:buffer';
const buf = Buffer.from('buffer');
console.log(buf.subarray(-6, -1).toString());
// Prints: buffe
// (Equivalent to buf.subarray(0, 5).)
console.log(buf.subarray(-6, -2).toString());
// Prints: buff
// (Equivalent to buf.subarray(0, 4).)
console.log(buf.subarray(-5, -2).toString());
// Prints: uff
// (Equivalent to buf.subarray(1, 4).)
+
+
+Optional
start: numberWhere the new Buffer
will start.
Optional
end: numberWhere the new Buffer
will end (not inclusive).
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.
import { Buffer } from 'node:buffer';
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf1);
// Prints: <Buffer 01 02 03 04 05 06 07 08>
buf1.swap16();
console.log(buf1);
// Prints: <Buffer 02 01 04 03 06 05 08 07>
const buf2 = Buffer.from([0x1, 0x2, 0x3]);
buf2.swap16();
// Throws ERR_INVALID_BUFFER_SIZE.
+
+
+One convenient use of buf.swap16()
is to perform a fast in-place conversion
+between UTF-16 little-endian and UTF-16 big-endian:
import { Buffer } from 'node:buffer';
const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
buf.swap16(); // Convert to big-endian UTF-16 text.
+
+
+A reference to buf
.
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.
import { Buffer } from 'node:buffer';
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf1);
// Prints: <Buffer 01 02 03 04 05 06 07 08>
buf1.swap32();
console.log(buf1);
// Prints: <Buffer 04 03 02 01 08 07 06 05>
const buf2 = Buffer.from([0x1, 0x2, 0x3]);
buf2.swap32();
// Throws ERR_INVALID_BUFFER_SIZE.
+
+
+A reference to buf
.
Interprets buf
as an array of 64-bit numbers and swaps byte order in-place.
+Throws ERR_INVALID_BUFFER_SIZE
if buf.length
is not a multiple of 8.
import { Buffer } from 'node:buffer';
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf1);
// Prints: <Buffer 01 02 03 04 05 06 07 08>
buf1.swap64();
console.log(buf1);
// Prints: <Buffer 08 07 06 05 04 03 02 01>
const buf2 = Buffer.from([0x1, 0x2, 0x3]);
buf2.swap64();
// Throws ERR_INVALID_BUFFER_SIZE.
+
+
+A reference to buf
.
Returns a JSON representation of buf
. JSON.stringify()
implicitly calls
+this function when stringifying a Buffer
instance.
Buffer.from()
accepts objects in the format returned from this method.
+In particular, Buffer.from(buf.toJSON())
works like Buffer.from(buf)
.
import { Buffer } from 'node:buffer';
const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
const json = JSON.stringify(buf);
console.log(json);
// Prints: {"type":"Buffer","data":[1,2,3,4,5]}
const copy = JSON.parse(json, (key, value) => {
return value && value.type === 'Buffer' ?
Buffer.from(value) :
value;
});
console.log(copy);
// Prints: <Buffer 01 02 03 04 05>
+
+
+Decodes buf
to a string according to the specified character encoding inencoding
. start
and end
may be passed to decode only a subset of buf
.
If encoding
is 'utf8'
and a byte sequence in the input is not valid UTF-8,
+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';
const buf1 = Buffer.allocUnsafe(26);
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'.
buf1[i] = i + 97;
}
console.log(buf1.toString('utf8'));
// Prints: abcdefghijklmnopqrstuvwxyz
console.log(buf1.toString('utf8', 0, 5));
// Prints: abcde
const buf2 = Buffer.from('tést');
console.log(buf2.toString('hex'));
// Prints: 74c3a97374
console.log(buf2.toString('utf8', 0, 3));
// Prints: té
console.log(buf2.toString(undefined, 0, 3));
// Prints: té
+
+
+Optional
encoding: BufferEncodingThe character encoding to use.
+Optional
start: numberThe byte offset to start decoding at.
+Optional
end: numberThe byte offset to stop decoding at (not inclusive).
+Returns an list of values in the array
+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.
import { Buffer } from 'node:buffer';
const buf = Buffer.alloc(256);
const len = buf.write('\u00bd + \u00bc = \u00be', 0);
console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
// Prints: 12 bytes: ½ + ¼ = ¾
const buffer = Buffer.alloc(10);
const length = buffer.write('abcd', 8);
console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
// Prints: 2 bytes : ab
+
+
+String to write to buf
.
Optional
encoding: BufferEncodingThe character encoding of string
.
Number of bytes written.
+Optional
encoding: BufferEncodingOptional
encoding: BufferEncodingWrites value
to buf
at the specified offset
as big-endian.
value
is interpreted and written as a two's complement signed integer.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(8);
buf.writeBigInt64BE(0x0102030405060708n, 0);
console.log(buf);
// Prints: <Buffer 01 02 03 04 05 06 07 08>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8
.
offset
plus the number of bytes written.
Writes value
to buf
at the specified offset
as little-endian.
value
is interpreted and written as a two's complement signed integer.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(8);
buf.writeBigInt64LE(0x0102030405060708n, 0);
console.log(buf);
// Prints: <Buffer 08 07 06 05 04 03 02 01>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(8);
buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
console.log(buf);
// Prints: <Buffer de ca fa fe ca ce fa de>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8
.
offset
plus the number of bytes written.
Writes value
to buf
at the specified offset
as little-endian
import { Buffer } from 'node:buffer';
const buf = 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.
Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(8);
buf.writeDoubleBE(123.456, 0);
console.log(buf);
// Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 8
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(8);
buf.writeDoubleLE(123.456, 0);
console.log(buf);
// Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 8
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(4);
buf.writeFloatBE(0xcafebabe, 0);
console.log(buf);
// Prints: <Buffer 4f 4a fe bb>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(4);
buf.writeFloatLE(0xcafebabe, 0);
console.log(buf);
// Prints: <Buffer bb fe 4a 4f>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(2);
buf.writeInt16BE(0x0102, 0);
console.log(buf);
// Prints: <Buffer 01 02>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(2);
buf.writeInt16LE(0x0304, 0);
console.log(buf);
// Prints: <Buffer 04 03>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2
.
offset
plus the number of bytes written.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(4);
buf.writeInt32BE(0x01020304, 0);
console.log(buf);
// Prints: <Buffer 01 02 03 04>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4
.
offset
plus the number of bytes written.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(4);
buf.writeInt32LE(0x05060708, 0);
console.log(buf);
// Prints: <Buffer 08 07 06 05>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4
.
offset
plus the number of bytes written.
Writes value
to buf
at the specified offset
. value
must be a valid
+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';
const buf = Buffer.allocUnsafe(2);
buf.writeInt8(2, 0);
buf.writeInt8(-2, 1);
console.log(buf);
// Prints: <Buffer 02 fe>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1
.
offset
plus the number of bytes written.
Writes byteLength
bytes of value
to buf
at the specified offset
as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined whenvalue
is anything other than a
+signed integer.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(6);
buf.writeIntBE(0x1234567890ab, 0, 6);
console.log(buf);
// Prints: <Buffer 12 34 56 78 90 ab>
+
+
+Number to be written to buf
.
Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to write. Must satisfy 0 < byteLength <= 6
.
offset
plus the number of bytes written.
Writes byteLength
bytes of value
to buf
at the specified offset
as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
+when value
is anything other than a signed integer.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(6);
buf.writeIntLE(0x1234567890ab, 0, 6);
console.log(buf);
// Prints: <Buffer ab 90 78 56 34 12>
+
+
+Number to be written to buf
.
Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to write. Must satisfy 0 < byteLength <= 6
.
offset
plus the number of bytes written.
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 value
is anything other than an
+unsigned 16-bit integer.
This function is also available under the writeUint16BE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(4);
buf.writeUInt16BE(0xdead, 0);
buf.writeUInt16BE(0xbeef, 2);
console.log(buf);
// Prints: <Buffer de ad be ef>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2
.
offset
plus the number of bytes written.
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.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(4);
buf.writeUInt16LE(0xdead, 0);
buf.writeUInt16LE(0xbeef, 2);
console.log(buf);
// Prints: <Buffer ad de ef be>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2
.
offset
plus the number of bytes written.
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 value
is anything other than an
+unsigned 32-bit integer.
This function is also available under the writeUint32BE
alias.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(4);
buf.writeUInt32BE(0xfeedface, 0);
console.log(buf);
// Prints: <Buffer fe ed fa ce>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4
.
offset
plus the number of bytes written.
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';
const buf = Buffer.allocUnsafe(4);
buf.writeUInt32LE(0xfeedface, 0);
console.log(buf);
// Prints: <Buffer ce fa ed fe>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4
.
offset
plus the number of bytes written.
Writes value
to buf
at the specified offset
. value
must be a
+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.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(4);
buf.writeUInt8(0x3, 0);
buf.writeUInt8(0x4, 1);
buf.writeUInt8(0x23, 2);
buf.writeUInt8(0x42, 3);
console.log(buf);
// Prints: <Buffer 03 04 23 42>
+
+
+Number to be written to buf
.
Optional
offset: numberNumber of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1
.
offset
plus the number of bytes written.
Writes byteLength
bytes of value
to buf
at the specified offset
as 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.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(6);
buf.writeUIntBE(0x1234567890ab, 0, 6);
console.log(buf);
// Prints: <Buffer 12 34 56 78 90 ab>
+
+
+Number to be written to buf
.
Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to write. Must satisfy 0 < byteLength <= 6
.
offset
plus the number of bytes written.
Writes byteLength
bytes of value
to buf
at the specified offset
as 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.
import { Buffer } from 'node:buffer';
const buf = Buffer.allocUnsafe(6);
buf.writeUIntLE(0x1234567890ab, 0, 6);
console.log(buf);
// Prints: <Buffer ab 90 78 56 34 12>
+
+
+Number to be written to buf
.
Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength
.
Number of bytes to write. Must satisfy 0 < byteLength <= 6
.
offset
plus the number of bytes written.
Raw data is stored in instances of the Buffer class. +A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. +Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'
+Allocates a new buffer containing the given {str}.
+String to store in buffer.
+Optional
encoding: BufferEncodingencoding to use, optional. Default is 'utf8'
+Allocates a new buffer of {size} octets.
+count of octets to allocate.
+Allocates a new buffer containing the given {array} of octets.
+The octets to store.
+Produces a Buffer backed by the same allocated memory as +the given {ArrayBuffer}/{SharedArrayBuffer}.
+The ArrayBuffer with which to share memory.
+Allocates a new buffer containing the given {array} of octets.
+The octets to store.
+Copies the passed {buffer} data onto a new {Buffer} instance.
+The buffer to copy.
+This is the size (in bytes) of pre-allocated internal Buffer
instances used
+for pooling. This value may be modified.
Allocates a new Buffer
of size
bytes. If fill
is undefined
, theBuffer
will be zero-filled.
import { Buffer } from 'node:buffer';
const buf = Buffer.alloc(5);
console.log(buf);
// Prints: <Buffer 00 00 00 00 00>
+
+
+If size
is larger than constants.MAX_LENGTH or smaller than 0, ERR_OUT_OF_RANGE
is thrown.
If fill
is specified, the allocated Buffer
will be initialized by calling buf.fill(fill)
.
import { Buffer } from 'node:buffer';
const buf = Buffer.alloc(5, 'a');
console.log(buf);
// Prints: <Buffer 61 61 61 61 61>
+
+
+If both fill
and encoding
are specified, the allocated Buffer
will be
+initialized by calling buf.fill(fill, encoding)
.
import { Buffer } from 'node:buffer';
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
console.log(buf);
// Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
+
+
+Calling Buffer.alloc()
can be measurably slower than the alternative Buffer.allocUnsafe()
but ensures that the newly created Buffer
instance
+contents will never contain sensitive data from previous allocations, including
+data that might not have been allocated for Buffer
s.
A TypeError
will be thrown if size
is not a number.
The desired length of the new Buffer
.
Optional
fill: string | number | Uint8ArrayA value to pre-fill the new Buffer
with.
Optional
encoding: BufferEncodingIf fill
is a string, this is its encoding.
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 not
+initialized. 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';
const buf = Buffer.allocUnsafe(10);
console.log(buf);
// Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
buf.fill(0);
console.log(buf);
// Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
+
+
+A TypeError
will be thrown if size
is not a number.
The Buffer
module pre-allocates an internal Buffer
instance of
+size Buffer.poolSize
that is used as a pool for the fast allocation of new Buffer
instances created using Buffer.allocUnsafe()
, Buffer.from(array)
,
+and Buffer.concat()
only when size
is less than Buffer.poolSize >>> 1
(floor of Buffer.poolSize
divided by two).
Use of this pre-allocated internal memory pool is a key difference between
+calling Buffer.alloc(size, fill)
vs. Buffer.allocUnsafe(size).fill(fill)
.
+Specifically, Buffer.alloc(size, fill)
will never use the internal Buffer
pool, while Buffer.allocUnsafe(size).fill(fill)
will use the internalBuffer
pool if size
is less
+than or equal to half Buffer.poolSize
. The
+difference is subtle but can be important when an application requires the
+additional performance that Buffer.allocUnsafe()
provides.
The desired length of the new Buffer
.
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. A zero-length Buffer
is created if
+size
is 0.
The underlying memory for Buffer
instances created in this way is not
+initialized. The contents of the newly created Buffer
are unknown and may contain sensitive data. Use buf.fill(0)
to initialize
+such Buffer
instances with zeroes.
When using Buffer.allocUnsafe()
to allocate new Buffer
instances,
+allocations under 4 KiB are sliced from a single pre-allocated Buffer
. This
+allows applications to avoid the garbage collection overhead of creating many
+individually allocated Buffer
instances. This approach improves both
+performance and memory usage by eliminating the need to track and clean up as
+many individual ArrayBuffer
objects.
However, in the case where a developer may need to retain a small chunk of
+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.
const store = [];
socket.on('readable', () => {
let data;
while (null !== (data = readable.read())) {
// Allocate for retained data.
const sb = 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.
The desired length of the new Buffer
.
Returns the byte length of a string when encoded using encoding
.
+This is not the same as String.prototype.length
, which does not account
+for the encoding that is used to convert the string into bytes.
For 'base64'
, 'base64url'
, and 'hex'
, this function assumes valid input.
+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.
import { Buffer } from 'node:buffer';
const str = '\u00bd + \u00bc = \u00be';
console.log(`${str}: ${str.length} characters, ` +
`${Buffer.byteLength(str, 'utf8')} bytes`);
// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
+
+
+When string
is a
+Buffer
/DataView
/[TypedArray
](https://developer.mozilla.org/en-US/docs/Web/JavaScript/-
+Reference/Global_Objects/TypedArray)/ArrayBuffer
/[SharedArrayBuffer
](https://develop-
+er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by .byteLength
is returned.
A value to calculate the length of.
+Optional
encoding: BufferEncodingIf string
is a string, this is its encoding.
The number of bytes contained within string
.
Compares buf1
to buf2
, typically for the purpose of sorting arrays of Buffer
instances. This is equivalent to calling buf1.compare(buf2)
.
import { Buffer } from 'node:buffer';
const buf1 = Buffer.from('1234');
const buf2 = Buffer.from('0123');
const arr = [buf1, buf2];
console.log(arr.sort(Buffer.compare));
// Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
// (This result is equal to: [buf2, buf1].)
+
+
+Either -1
, 0
, or 1
, depending on the result of the comparison. See compare
for details.
Returns a new Buffer
which is the result of concatenating all the Buffer
instances in the list
together.
If the list has no items, or if the totalLength
is 0, then a new zero-length Buffer
is returned.
If totalLength
is not provided, it is calculated from the Buffer
instances
+in list
by adding their lengths.
If totalLength
is provided, it is coerced to an unsigned integer. If the
+combined length of the Buffer
s 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.
const buf1 = Buffer.alloc(10);
const buf2 = Buffer.alloc(14);
const buf3 = Buffer.alloc(18);
const totalLength = buf1.length + buf2.length + buf3.length;
console.log(totalLength);
// Prints: 42
const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
console.log(bufA);
// Prints: <Buffer 00 00 00 00 ...>
console.log(bufA.length);
// Prints: 42
+
+
+Buffer.concat()
may also use the internal Buffer
pool like Buffer.allocUnsafe()
does.
List of Buffer
or Uint8Array instances to concatenate.
Optional
totalLength: numberTotal length of the Buffer
instances in list
when concatenated.
Copies the underlying memory of view
into a new Buffer
.
const u16 = new Uint16Array([0, 0xffff]);
const buf = Buffer.copyBytesFrom(u16, 1, 1);
u16[1] = 0;
console.log(buf.length); // 2
console.log(buf[0]); // 255
console.log(buf[1]); // 255
+
+
+The {TypedArray} to copy.
+Optional
offset: numberThe starting offset within view
.
Optional
length: numberThe number of elements from view
to copy.
Allocates a new Buffer
using an array
of bytes in the range 0
– 255
.
+Array entries outside that range will be truncated to fit into it.
import { Buffer } from 'node:buffer';
// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
+
+
+If array
is an Array
-like object (that is, one with a length
property of
+type number
), it is treated as if it is an array, unless it is a Buffer
or
+a Uint8Array
. This means all other TypedArray
variants get treated as an Array
. To create a Buffer
from the bytes backing a TypedArray
, use Buffer.copyBytesFrom()
.
A TypeError
will be thrown if array
is not an Array
or another type
+appropriate for Buffer.from()
variants.
Buffer.from(array)
and Buffer.from(string)
may also use the internal Buffer
pool like Buffer.allocUnsafe()
does.
Optional
byteOffset: numberOptional
length: numberCreates a new Buffer using the passed {data}
+data to create a new Buffer
+Creates a new Buffer containing the given JavaScript string {str}. +If provided, the {encoding} parameter identifies the character encoding. +If not provided, {encoding} defaults to 'utf8'.
+Optional
encoding: BufferEncodingReturns true
if obj
is a Buffer
, false
otherwise.
import { Buffer } from 'node:buffer';
Buffer.isBuffer(Buffer.alloc(10)); // true
Buffer.isBuffer(Buffer.from('foo')); // true
Buffer.isBuffer('a string'); // false
Buffer.isBuffer([]); // false
Buffer.isBuffer(new Uint8Array(1024)); // false
+
+
+Returns true
if encoding
is the name of a supported character encoding,
+or false
otherwise.
import { Buffer } from 'node:buffer';
console.log(Buffer.isEncoding('utf8'));
// Prints: true
console.log(Buffer.isEncoding('hex'));
// Prints: true
console.log(Buffer.isEncoding('utf/8'));
// Prints: false
console.log(Buffer.isEncoding(''));
// Prints: false
+
+
+A character encoding name to check.
+Optional
[captureAlias for emitter.on(eventName, listener)
.
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.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = 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
+
+
+Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Adds the listener
function to the end of the listeners array for 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.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+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.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+Adds a one-time listener
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!');
});
+
+
+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.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+Adds the listener
function to the beginning of the listeners array for 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.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
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!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = 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
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Removes the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+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.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// 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
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+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:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: [] | [TNext]Rest
...args: [] | [undefined]Optional
returnOptional
value: anyOptional
throwOptional
e: anyRest
...args: [] | [TNext]Optional
returnOptional
value: TReturnOptional
throwOptional
e: anyOptional
cacheWhether or not to cache resolved templates. Defaults to false
.
Optional
catchCatch all errors instead of exit upon one. Please note that render errors won't be reached when parse fails.
+Default date format to use if the date filter doesn't include a format. Defaults to %A, %B %-e, %Y at %-l:%M %P %z
.
If set, treat the filepath
parameter in {%include filepath %}
and {%layout filepath%}
as a variable, otherwise as a literal value. Defaults to true
.
Add a extname (if filepath doesn't include one) before template file lookup. Eg: setting to ".html"
will allow including file by basename. Defaults to ""
.
fs
is used to override the default file-system module with a custom implementation.
the global scope passed down to all partial and layout templates, i.e. templates included by include
, layout
and render
tags.
Whether trim*Left
/trim*Right
is greedy. When set to true
, all consecutive blank characters including \n
will be trimmed regardless of line breaks. Defaults to true
.
Use jekyll style include, pass parameters to include
variable of current scope. Defaults to false
.
Optional
jekyllUse jekyll style where filter, enables array item match. Defaults to false
.
Use JavaScript Truthiness. Defaults to false
.
Whether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to false
.
Optional
keykeyValue separator
+A directory or an array of directories from where to resolve layout templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to root
Modifies the behavior of strictVariables
. If set, a single undefined variable will not cause an exception in the context of the if
/elsif
/unless
tag and the default
filter. Instead, it will evaluate to false
and null
, respectively. Irrelevant if strictVariables
is not set. Defaults to false
. *
Default locale, will be used by date filter. Defaults to system locale.
+For DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue.
+An object of operators for conditional statements. Defaults to the regular Liquid operators.
+Optional
orderedRespect parameter order when using filters like "for ... reversed limit", Defaults to false
.
The left delimiter for liquid outputs. *
+The right delimiter for liquid outputs. *
+Optional
outputDefault escape filter applied to output values, when set, you'll have to add | raw
for values don't need to be escaped. Defaults to undefined
.
Hide scope variables from prototypes, useful when you're passing a not sanitized object into LiquidJS or need to hide prototypes from templates.
+For DoS handling, limit total length of templates parsed in one parse()
call. A typical PC can handle 1e8 (100M) characters without issues.
A directory or an array of directories from where to resolve included templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to root
Whether input strings to date filter preserve the given timezone *
+Allow refer to layouts/partials by relative pathname. To avoid arbitrary filesystem read, paths been referenced also need to be within corresponding root, partials, layouts. Defaults to true
.
For DoS handling, limit total time (in ms) for each render()
call.
A directory or an array of directories from where to resolve layout and include templates, and the filename passed to .renderFile()
. If it's an array, the files are looked up in the order they occur in the array. Defaults to ["."]
Whether or not to assert filter existence. If set to false
, undefined filters will be skipped. Otherwise, undefined filters will cause an exception. Defaults to false
.
Whether or not to assert variable existence. If set to false
, undefined variables will be rendered as empty string. Otherwise, undefined variables will cause an exception. Defaults to false
.
The left delimiter for liquid tags. *
+The right delimiter for liquid tags. *
+Optional
templatesRender from in-memory templates
mapping instead of file system. File system related options like fs
, 'root', and relativeReference
will be ignored when templates
is specified.
Optional
timezoneJavaScript timezone name or timezoneOffset for date
filter, default to local time. That means if you're in Australia (UTC+10), it'll default to -600
or Australia/Lindeman
Similar to trimOutputRight
, whereas the \n
is exclusive. Defaults to false
. See Whitespace Control for details.
Strip blank characters (including
, \t
, and \r
) from the right of values ({{ }}
) until \n
(inclusive). Defaults to false
.
Similar to trimTagRight
, whereas the \n
is exclusive. Defaults to false
. See Whitespace Control for details.
Strip blank characters (including
, \t
, and \r
) from the right of tags ({% %}
) until \n
(inclusive). Defaults to false
.
Optional
cacheWhether or not to cache resolved templates. Defaults to false
.
Optional
catchCatch all errors instead of exit upon one. Please note that render errors won't be reached when parse fails.
+Optional
dateDefault date format to use if the date filter doesn't include a format. Defaults to %A, %B %-e, %Y at %-l:%M %P %z
.
Optional
dynamicIf set, treat the filepath
parameter in {%include filepath %}
and {%layout filepath%}
as a variable, otherwise as a literal value. Defaults to true
.
Optional
extnameAdd a extname (if filepath doesn't include one) before template file lookup. Eg: setting to ".html"
will allow including file by basename. Defaults to ""
.
Optional
fsfs
is used to override the default file-system module with a custom implementation.
Optional
globalsthe global scope passed down to all partial and layout templates, i.e. templates included by include
, layout
and render
tags.
Optional
greedyWhether trim*Left
/trim*Right
is greedy. When set to true
, all consecutive blank characters including \n
will be trimmed regardless of line breaks. Defaults to true
.
Optional
jekyllUse jekyll style include, pass parameters to include
variable of current scope. Defaults to false
.
Optional
jekyllUse jekyll style where filter, enables array item match. Defaults to false
.
Optional
jsUse JavaScript Truthiness. Defaults to false
.
Optional
keepWhether or not to keep value type when writing the Output, not working for streamed rendering. Defaults to false
.
Optional
keykeyValue separator
+Optional
layoutsA directory or an array of directories from where to resolve layout templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to root
Optional
lenientModifies the behavior of strictVariables
. If set, a single undefined variable will not cause an exception in the context of the if
/elsif
/unless
tag and the default
filter. Instead, it will evaluate to false
and null
, respectively. Irrelevant if strictVariables
is not set. Defaults to false
. *
Optional
localeDefault locale, will be used by date filter. Defaults to system locale.
+Optional
memoryFor DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue.
+Optional
operatorsAn object of operators for conditional statements. Defaults to the regular Liquid operators.
+Optional
orderedRespect parameter order when using filters like "for ... reversed limit", Defaults to false
.
Optional
outputThe left delimiter for liquid outputs. *
+Optional
outputThe right delimiter for liquid outputs. *
+Optional
outputDefault escape filter applied to output values, when set, you'll have to add | raw
for values don't need to be escaped. Defaults to undefined
.
Optional
ownHide scope variables from prototypes, useful when you're passing a not sanitized object into LiquidJS or need to hide prototypes from templates.
+Optional
parseFor DoS handling, limit total length of templates parsed in one parse()
call. A typical PC can handle 1e8 (100M) characters without issues.
Optional
partialsA directory or an array of directories from where to resolve included templates. If it's an array, the files are looked up in the order they occur in the array. Defaults to root
Optional
preserveWhether input strings to date filter preserve the given timezone *
+Optional
relativeAllow refer to layouts/partials by relative pathname. To avoid arbitrary filesystem read, paths been referenced also need to be within corresponding root, partials, layouts. Defaults to true
.
Optional
renderFor DoS handling, limit total time (in ms) for each render()
call.
Optional
rootA directory or an array of directories from where to resolve layout and include templates, and the filename passed to .renderFile()
. If it's an array, the files are looked up in the order they occur in the array. Defaults to ["."]
Optional
strictWhether or not to assert filter existence. If set to false
, undefined filters will be skipped. Otherwise, undefined filters will cause an exception. Defaults to false
.
Optional
strictWhether or not to assert variable existence. If set to false
, undefined variables will be rendered as empty string. Otherwise, undefined variables will cause an exception. Defaults to false
.
Optional
tagThe left delimiter for liquid tags. *
+Optional
tagThe right delimiter for liquid tags. *
+Optional
templatesRender from in-memory templates
mapping instead of file system. File system related options like fs
, 'root', and relativeReference
will be ignored when templates
is specified.
Optional
timezoneJavaScript timezone name or timezoneOffset for date
filter, default to local time. That means if you're in Australia (UTC+10), it'll default to -600
or Australia/Lindeman
Optional
trimSimilar to trimOutputRight
, whereas the \n
is exclusive. Defaults to false
. See Whitespace Control for details.
Optional
trimStrip blank characters (including
, \t
, and \r
) from the right of values ({{ }}
) until \n
(inclusive). Defaults to false
.
Optional
trimSimilar to trimTagRight
, whereas the \n
is exclusive. Defaults to false
. See Whitespace Control for details.
Optional
trimStrip blank characters (including
, \t
, and \r
) from the right of tags ({% %}
) until \n
(inclusive). Defaults to false
.
Attaches callbacks for the resolution and/or rejection of the Promise.
+Optional
onfulfilled: null | ((value: T) => TResult1 | PromiseLike<TResult1>)The callback to execute when the Promise is resolved.
+Optional
onrejected: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)The callback to execute when the Promise is rejected.
+A Promise for the completion of which ever callback is executed.
+Optional
[captureAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]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.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = 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
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for 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.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+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.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
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!');
});
+
+
+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.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for 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.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]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!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = 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
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+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.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// 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
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+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:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
destination: WritableStreamOptional
encoding: BufferEncodingOptional
globalsSame as globals
on LiquidOptions, but only for current render() call
Optional
lookupOptional
memoryFor DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue..
+Optional
ownSame as ownPropertyOnly
on LiquidOptions, but only for current render() call
Optional
renderFor DoS handling, limit total time (in ms) for each render()
call.
Optional
strictSame as strictVariables
on LiquidOptions, but only for current render() call
Optional
syncThis call is sync or async? It's used by Liquid internal methods, you'll not need this.
+Optional
templateFor DoS handling, limit total renders of tag/HTML/output in one render()
call. A typical PC can handle 1e5 renders of typical templates per second.
Optional
globalsSame as globals
on LiquidOptions, but only for current render() call
Optional
memoryFor DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue..
+Optional
ownSame as ownPropertyOnly
on LiquidOptions, but only for current render() call
Optional
renderFor DoS handling, limit total time (in ms) for each render()
call.
Optional
strictSame as strictVariables
on LiquidOptions, but only for current render() call
Optional
syncThis call is sync or async? It's used by Liquid internal methods, you'll not need this.
+Optional
templateFor DoS handling, limit total renders of tag/HTML/output in one render()
call. A typical PC can handle 1e5 renders of typical templates per second.
Readonly
[species]Readonly
[toReadonly
byteRead-only. The length of the ArrayBuffer (in bytes).
+Returns a section of an SharedArrayBuffer.
+Optional
end: numberOptional
parseOptional
[captureAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]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.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = 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
+
+
+Rest
...args: AnyRestOptional
cb: (() => void)Optional
cb: (() => void)Optional
encoding: BufferEncodingOptional
cb: (() => void)Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for 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.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+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.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
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!');
});
+
+
+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.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for 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.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]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!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = 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
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+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.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// 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
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+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:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
encoding: BufferEncodingOptional
cb: ((err?: null | Error) => void)Optional
err: null | ErrorProperty names and array indexes that make up a path to a variable.
+A mapping of variable names to an array of locations at which the variable was found.
+A variable's segments as an array, possibly with nested arrays of segments.
+Const
Const
Const
Const
Optional override for formatting stack traces
+