{"id":13431779,"url":"https://github.com/ben-bradley/fifo-array","last_synced_at":"2025-04-15T13:41:07.238Z","repository":{"id":18246267,"uuid":"21398106","full_name":"ben-bradley/fifo-array","owner":"ben-bradley","description":"A small bit of code to create fixed-length, first-in-first-out arrays in JavaScript.","archived":false,"fork":false,"pushed_at":"2014-08-25T14:37:08.000Z","size":152,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T23:21:15.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ben-bradley.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-01T18:25:47.000Z","updated_at":"2018-12-10T23:03:33.000Z","dependencies_parsed_at":"2022-09-26T21:50:31.705Z","dependency_job_id":null,"html_url":"https://github.com/ben-bradley/fifo-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ben-bradley%2Ffifo-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ben-bradley%2Ffifo-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ben-bradley%2Ffifo-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ben-bradley%2Ffifo-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ben-bradley","download_url":"https://codeload.github.com/ben-bradley/fifo-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249081543,"owners_count":21209716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:01:05.830Z","updated_at":"2025-04-15T13:41:07.220Z","avatar_url":"https://github.com/ben-bradley.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# fifo-array [![NPM](https://nodei.co/npm/fifo-array.png)](https://nodei.co/npm/fifo-array/) [![Build Status](https://secure.travis-ci.org/ben-bradley/fifo-array.png)](http://travis-ci.org/ben-bradley/fifo-array)\n\nA fixed-length, first-in-first-out array for Javascript.\n\n## Install\n\n`npm install fifo-array`\n\n-or-\n\n`npm install ben-bradley/fifo-array`\n\n## Methods\n\nAll `FifoArray` methods behave exactly like the `Array.prototype` methods, but they trim the array down to have a `length` equal to the `max`.  Which end of the array that is trimmed is the difference:\n\n- __FifoArray.push()__ - Trims from the front of the array until `length === max`.\n- __FifoArray.unshift()__ - Trims from the back of the array until `length === max`.\n- __FifoArray.splice()__ - Trims from the back of the array until `length === max`.\n\nAll other `Array.prototype` methods are untouched and will behave as expected.  I couldn't find any other methods that could add elements to the `FifoArray`\n\n## Examples\n\n### Basic usage\n\n```js\nvar FifoArray = require('fifo-array');\n\nvar fifoArray = new FifoArray(3, [ 'a', 'b', 'c', 'd' ]);\nconsole.log(fifoArray); // =\u003e [ 'b', 'c', 'd' ]\nconsole.log('max:', fifoArray.max); // =\u003e max: 3\nfifoArray.push(1, 2);\nconsole.log(fifoArray); // =\u003e [ 'd', 1, 2 ]\n```\n\n### #push()\n\n```js\nvar fifoArray = new FifoArray(3);\nfifoArray.push(2, 3, 4, 5);\nconsole.log(fifoArray); // =\u003e [ 3, 4, 5 ]\n```\n\n### #unshift()\n\n```js\nvar fifoArray = new FifoArray(3, [ 0, 1, 2 ]);\nfifoArray.unshift('a', 'b');\nconsole.log(fifoArray); // =\u003e [ 'a', 'b', 0 ]\n```\n\n### #splice()\n\n```js\nvar fifoArray = new FifoArray(3, [ 0, 1, 2 ]);\nfifoArray.splice(1, 2, 'a'); // at position 1, remove 2 elements and add 'a'\nconsole.log(fifoArray); // =\u003e [ 0, 'a' ]\n\nfifoArray.splice(1, 0, 'b'); // at posotion 1, remove 0 elements and add 'b'\nconsole.log(fifoArray); // =\u003e [ 0, 'b', 'a' ]\n```\n\n### .max\n\n```js\n// if necessary, it chops the array down to the new max\nvar fifoArray = new FifoArray(5, [ 0, 1, 2, 3, 4 ]);\nconsole.log(fifoArray); // =\u003e [ 0, 1, 2, 3, 4 ]\nfifoArray.max = 3;\nconsole.log('new max:', fifoArray.max); // =\u003e new max: 3\nconsole.log(fifoArray); // =\u003e [ 0, 1, 2 ]\n\nfifoArray.max = 10;\nfifoArray.push('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');\nconsole.log(fifoArray); // =\u003e [ 1, 2, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ]\n```\n\n## Version History\n\n- 0.1.2 - Added readme.md bling\n- 0.1.1 - Initial release\n- 0.0.* - Internal development\n\n## References\n\nHere are several sources that helped me write this module:\n\n- http://www.bennadel.com/blog/2308-creating-a-fixed-length-queue-in-javascript-using-arrays.htm\n- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty\n- https://variadic.me/posts/2013-10-22-bind-call-and-apply-in-javascript.html\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fben-bradley%2Ffifo-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fben-bradley%2Ffifo-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fben-bradley%2Ffifo-array/lists"}