{"id":20080769,"url":"https://github.com/malpercio/data-holder","last_synced_at":"2025-03-02T13:24:39.479Z","repository":{"id":69965271,"uuid":"80881527","full_name":"malpercio/data-holder","owner":"malpercio","description":"A NodeJS package that provides implementations of some data structures","archived":false,"fork":false,"pushed_at":"2017-04-24T22:13:37.000Z","size":95,"stargazers_count":0,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T12:53:41.171Z","etag":null,"topics":["data-structures","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malpercio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-04T00:37:06.000Z","updated_at":"2017-02-04T00:49:56.000Z","dependencies_parsed_at":"2023-02-27T21:45:13.503Z","dependency_job_id":null,"html_url":"https://github.com/malpercio/data-holder","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malpercio%2Fdata-holder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malpercio%2Fdata-holder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malpercio%2Fdata-holder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malpercio%2Fdata-holder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malpercio","download_url":"https://codeload.github.com/malpercio/data-holder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241511334,"owners_count":19974398,"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":["data-structures","nodejs"],"created_at":"2024-11-13T15:29:56.341Z","updated_at":"2025-03-02T13:24:39.466Z","avatar_url":"https://github.com/malpercio.png","language":"JavaScript","readme":"[![Stories in Ready](https://badge.waffle.io/malpercio/data-holder.png?label=ready\u0026title=Ready)](https://waffle.io/malpercio/data-holder)\n[![Build Status](https://travis-ci.org/malpercio/data-holder.svg?branch=master)](https://travis-ci.org/malpercio/data-holder)\n[![Build Status](https://david-dm.org/malpercio/data-holder.svg)](https://travis-ci.org/malpercio/data-holder)\n[![DevDependencies](https://david-dm.org/malpercio/data-holder/dev-status.svg)](https://david-dm.org/malpercio/data-holder)\n[![npm version](https://badge.fury.io/js/data-holder.svg)](https://badge.fury.io/js/data-holder)\n\n# data-holder\nA NodeJS package that provides asynchronous implementations for some data structures, with the flexibility needed in this cruel world divided by callbacks and promises.\n\nYou can find the complete docs in **[here](https://github.com/malpercio/data-holder/wiki/)**.\n\n## Implemented structures\n* Linked list\n* Double linked list\n* Ordered List\n* Stack\n* Queue\n\n## A little introduction\nLet's start simple, say you want a semi **synchronous** process (recommended mostly for short lived experiments and tests).\n\n```js\nlet structures = require(data-holder)('Sync');\nlet List = structures.List;\n\n//Blah, blah, blah...\n\nlet l = new List();                                        // []\nl.add(13);                                                 // [13]\n\n//Another important thing\n\nl.unshift(42);                                             // [42, 13]\n\n//Here you must put code that is definitively not going to crash.\n\nconsole.log(l.pop());                                      // [42]\n```\n\nBut... what about **callbacks**?\n```js\nlet structures = require(data-holder)();\nlet List = structures.List;\n\n//Blah, blah, blah...\n\n//You simply pass the callback as an extra parameter.\nlet l = new List();                                        // []\nl.add(13, () =\u003e {                                          // [42, 13]\n    l.unshift(42, () =\u003e {\n      l.pop((err, element) =\u003e {                            // [42]\n        console.log(element);\n      });                                      \n    });\n});\n```\nAnd do not panic, I won't forget about **promises**.\nIf you want to use the ones implemented by default on Node, this example is for you.\n```js\nlet structures = require(data-holder)();\nlet List = structures.List;\n\n//Blah, blah, blah...\n\n//You simply pass the callback as an extra parameter.\nlet l = new List();                                        // []\nlet p1 = l.add(13);                                        // [13]\nlet p2 = p1.then(() =\u003e {\n  return l.unshift(42);                                    // [42, 13]\n});\nlet p3 = p2.then(() =\u003e {\n  return l.pop();                                          // [42]\n});\n\np3\n  .then((element) =\u003e {\n    console.log(element);\n  })\n  .catch(() =\u003e {\n    console.log(\"):\");\n  });\n```\nJust as a pro-tip, you can also pass the string `default` or `Default` and get the same behaviour (callbacks and Node's promise).\n\n\nBut maybe, you are already using a promise library, then send the function through parameter. Don't worry, I'm pretty bad at explaining, let's see it it action (with **Bluebird**)\n```js\nlet Promise = require('bluebird');\nlet structures = require(data-holder)(Promise);\nlet List = structures.List;\n\n//Blah, blah, blah...\n\n//You simply pass the callback as an extra parameter.\nlet l = new List();                                        // []\nlet p1 = l.add(13);                                        // [13]\nlet p2 = p1.then(() =\u003e {\n  return l.unshift(42);                                    // [42, 13]\n});\nlet p3 = p2.then(() =\u003e {\n  return l.pop();                                          // [42]\n});\n\np3\n  .then((element) =\u003e {\n    console.log(element);\n  })\n  .catch(() =\u003e {\n    console.log(\"):\");\n  });\n```\nAnd that's how you use it with Bluebird. And, yes, I didn't bothered to change the example.\n\nAlso, you don't need to import all of the structures (which we have been doing on the previous examples). Let's say you only need a **list with callbacks**; the second parameter must be a string with the name of the structure. Be careful, this returns the structure directly.\n```js\nlet List = require(data-holder)('Default', 'List');\n\n//Blah, blah, bla\n\n//You simply pass the callback as an extra parameter.\nlet l = new List();                                        // []\nl.add(13, () =\u003e {                                          // [42, 13]\n    l.unshift(42, () =\u003e {\n      l.pop((err, element) =\u003e {                            // [42]\n        console.log(element);\n      });                                      \n    });\n});\n```\n\nAlso, you might need **more than one structure at the same time**, to require them is as simple as passing an array of strings. It gives you the same arrangement as if you imported all of the structures available.\n```js\nlet data-holder = require(data-holder)('Default', 'List', 'OrderedList');\nlet List = structures.List;\nlet OrderedList = structures.OrderedList;\n\n//Blah, blah, blah...\n\n//You simply pass the callback as an extra parameter.\nlet l = new List();                                        // []\nlet l2 = new OrderedList();                                // []\nl.add(13, () =\u003e {                                          // [42, 13]\n    l.unshift(42, () =\u003e {\n      l.pop((err, element) =\u003e {                            // [42]\n        console.log(element);\n      });                                      \n    });\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalpercio%2Fdata-holder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalpercio%2Fdata-holder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalpercio%2Fdata-holder/lists"}