{"id":17398214,"url":"https://github.com/codeman99/callpack","last_synced_at":"2025-03-27T22:16:17.646Z","repository":{"id":57193194,"uuid":"66738906","full_name":"CodeMan99/callpack","owner":"CodeMan99","description":"Pack multi-value callback results into a single argument.","archived":false,"fork":false,"pushed_at":"2018-03-14T06:37:14.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T00:51:24.034Z","etag":null,"topics":["callback"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeMan99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-27T22:50:08.000Z","updated_at":"2018-03-14T06:37:15.000Z","dependencies_parsed_at":"2022-09-01T06:01:38.157Z","dependency_job_id":null,"html_url":"https://github.com/CodeMan99/callpack","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Fcallpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Fcallpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Fcallpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Fcallpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeMan99","download_url":"https://codeload.github.com/CodeMan99/callpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245931897,"owners_count":20695964,"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":["callback"],"created_at":"2024-10-16T14:42:26.710Z","updated_at":"2025-03-27T22:16:17.613Z","avatar_url":"https://github.com/CodeMan99.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"callpack [![Build Status](https://travis-ci.org/CodeMan99/callpack.svg?branch=master)](https://travis-ci.org/CodeMan99/callpack)\n========\n\nSimply wraps a callback to \"pack\" multiple values into a single object.\n\nUsage\n-----\n\nCallpack packs values into an array-like object by default.\n\n    callpack(function(err, result) {\n      console.log(result[0] === 1);       // true\n      console.log(result[1] === 2);       // true\n      console.log(result.length);         // 2\n      console.log(Array.isArray(result)); // false\n      console.log(Array.from(result));    // [1, 2]\n      console.log(result.toString());     // \"[object Pack]\"\n    })(null, 1, 2);\n\nCallpack packs values into a simple object when you provide names.\n\n    callpack(function(err, result) {\n      console.log(result.first);  // \"Bill\"\n      console.log(result.second); // \"Thornton\"\n    }, 'first', 'second')(null, 'Bill', 'Thornton');\n\nRealistic example use case.\n\n    var async = require('async');\n    var callpack = require('callpack');\n    var fs = require('fs');\n    var request = require('request');\n\n    async.auto({\n      'page': cb =\u003e request('http://www.google.com', callpack(cb, 'response', 'body')),\n      'save': ['page', (result, cb) =\u003e {\n        if (result.page.response.statusCode == 200) {\n          fs.writeFile('./index.html', result.page.body, cb);\n        } else {\n          cb(result.page.response.statusMessage);\n        }\n      }]\n    });\n\nPromisifying a callback library.\n\n    var callpack = require('callpack');\n    var promisify = require('es6-promisify');\n    var _request = require('request');\n    var request = promisify(function() {\n      var cbIndex = arguments.length - 1;\n      arguments[cbIndex] = callpack(arguments[cbIndex], 'response', 'body');\n\n      _request.apply(_request, arguments);\n    });\n\n    request('http://www.google.com').then(result =\u003e console.log(result.body), console.error);\n\nReasoning\n---------\n\nConsuming an asynchronous function allows for flexibility, but often tools like\nthe awesome async library are easier to use with only a single value. How the\nfunction is consumed should be up to the developer, not the library.\n\nThus callpack doesn't make any assumptions like \"multiple values means an array\".\nInstead the decision is still up the end developer. You may use the result from\ncallpack as array, convert into an array, or use it to get an object that\nclosely mimics spreading the arguments over a function.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeman99%2Fcallpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeman99%2Fcallpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeman99%2Fcallpack/lists"}