{"id":22980488,"url":"https://github.com/kcartlidge/nowrap","last_synced_at":"2025-04-02T09:40:23.237Z","repository":{"id":145848571,"uuid":"47722315","full_name":"kcartlidge/nowrap","owner":"kcartlidge","description":"Wraps the top level functions of a Javascript object to allow before/after intercepts. Supports parameter substitutions via value or function.","archived":false,"fork":false,"pushed_at":"2016-04-08T05:54:27.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T11:37:35.426Z","etag":null,"topics":["javascript","wrap"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kcartlidge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2015-12-09T22:12:28.000Z","updated_at":"2023-04-11T15:18:24.000Z","dependencies_parsed_at":"2024-08-01T16:45:15.905Z","dependency_job_id":null,"html_url":"https://github.com/kcartlidge/nowrap","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kcartlidge%2Fnowrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kcartlidge%2Fnowrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kcartlidge%2Fnowrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kcartlidge%2Fnowrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kcartlidge","download_url":"https://codeload.github.com/kcartlidge/nowrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246792391,"owners_count":20834920,"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":["javascript","wrap"],"created_at":"2024-12-15T01:43:41.301Z","updated_at":"2025-04-02T09:40:23.218Z","avatar_url":"https://github.com/kcartlidge.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NoWrap v0.3.5\n## Wraps the top level functions of a Javascript object to allow before/after intercepts. Supports parameter substitutions via value or function.\n\n[By K Cartlidge](http://www.kcartlidge.com).\n\n### Licence\n\n[MIT Licence (very permissive)](http://opensource.org/licenses/MIT).\n[See the GitHub licence summary bullet points here](http://choosealicense.com/licenses/mit/).\n\nA copy of the licence is within the package source.\n\n### Current Status\n\n* Tested and working.\n* Includes optional parameter substitutions.\n\n### What Problem does it Solve?\n\nIt allows you to intercept calls to functions (on your own objects/modules\nor core/third party ones) and register handlers which get called before\nand/or after the intercepted one.\n\nThe real thing behaves as normal. Your *before* hook is told all the original\nparameters. Your *after* hook is told the result.\n\n## Installation\n\nIt's an npm module:\n\n``` sh\nnpm install nowrap\n```\n\n## Usage:\n\nRequire *nowrap* and the thing you want to wrap:\n\n``` javascript\nvar wrap = require('nowrap');\n\n// Load a module to use as an example.\nvar path = require('path');\n```\n\nCreate either/both your *before* and *after* hooks:\n\n``` javascript\n// Create a function to be called before a wrapped one.\nvar beforeFunc = function (name, args) {\n\tconsole.log(\"Actually calling '\" + name + \"' with \", args);\n};\n\n// Create a function to be called after a wrapped one.\nvar afterFunc = function (name, result) {\n\tconsole.log(\"The call returned:\", result);\n};\n```\n\nCreate any *substitutions* required for parameters.\nUsing these, you can dynamically alter what the function\nis given and so influence the result:\n\n``` javascript\n// The path goes uppercase.\n// The ext becomes '.ORIGINAL'.\nvar substitutions = {\n\tbasename: {\n\t\tpath: function(original) {\n\t\t\treturn original.toUpperCase();\n\t\t},\n\t\text: '.ORIGINAL'\n\t}\n};\n```\nThis is an object whose top level name should be the name\nof the function for which the substitution occurs. Within\nthat, the next nested name is the parameter name and the\nthat contains the value to be fed to the parameter.\n\nIf the value is anything *other* than a function it is fed\nin unchanged. If it is a *function* it is called with the value\nthat would normally be passed at this time, and is expected to\nthen return a replacement for passing in instead.\n\nIn the example above, when *basename.path('file.original','.ext')* is called\nthen 'file.original' is changed to 'FILE.ORIGINAL' via the function and '.ext' is changed\nto '.ORIGINAL' via the value substitution.\n\nWrap the thing and use it:\n\n``` javascript\n// Wrap the main functions and re-run.\nwrap(path, beforeFunc, afterFunc, substitutions);\nconsole.log(\"Appears to be calling 'basename' with ('/path/file.original', '.ext').\");\nvar result = path.basename('/path/file.original', '.ext');\n```\n\nThe output is similar to:\n\n\tAppears to be calling 'basename' with ('/path/file.original', '.ext').\n\tActually calling 'basename' with  [ path: '/PATH/FILE.ORIGINAL', ext: '.ORIGINAL' ]\n\tThe call returned: FILE\n\nThe args passed to the *before* function, being an associative\narray, can also be accessed as so:\n\n``` javascript\nvar beforeFunc = function(name, args) {\n\tconsole.log(args.path);\n};\n```\n\n## Test Coverage\n\nYou can run the tests using *npm*:\n\n``` sh\nnpm test\n```\n\n## Examples\n\n[You can try it live on the npm page](https://www.npmjs.com/package/nowrap).\nThis will run the *tonic-example.js* file (which is included).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkcartlidge%2Fnowrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkcartlidge%2Fnowrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkcartlidge%2Fnowrap/lists"}