{"id":16247220,"url":"https://github.com/dotnetcarpenter/npm-detectionizr","last_synced_at":"2025-04-08T11:49:37.527Z","repository":{"id":6870458,"uuid":"8119470","full_name":"dotnetCarpenter/npm-detectionizr","owner":"dotnetCarpenter","description":"Detect npm modules and system libraries with the same ease as Modernizr.","archived":false,"fork":false,"pushed_at":"2013-08-18T22:19:05.000Z","size":248,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T23:15:41.446Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotnetCarpenter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-WTFPL","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-10T05:36:50.000Z","updated_at":"2013-10-17T21:56:24.000Z","dependencies_parsed_at":"2022-09-25T04:00:28.034Z","dependency_job_id":null,"html_url":"https://github.com/dotnetCarpenter/npm-detectionizr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnetCarpenter%2Fnpm-detectionizr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnetCarpenter%2Fnpm-detectionizr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnetCarpenter%2Fnpm-detectionizr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnetCarpenter%2Fnpm-detectionizr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotnetCarpenter","download_url":"https://codeload.github.com/dotnetCarpenter/npm-detectionizr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838415,"owners_count":21004576,"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-10-10T14:36:20.823Z","updated_at":"2025-04-08T11:49:37.504Z","avatar_url":"https://github.com/dotnetCarpenter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"detectionizr\n============\n\nDetect npm modules and system libraries with the same ease as Modernizr.\n## Getting Started\nInstall the module with: `npm install detectionizr`\n\nThe one liner:\n```javascript\nvar d = require('detectionizr').detect(['html-doc', 'html-md']) // that's it!\n```\nNow you could do this:\n```javascript\nd['html-doc'] ?                   // is html-doc available?\n  d['html-doc'].parse(markdown) : // then use it\n    d['html-md'] ?                // if not, is html-md available?\n      d['html-md'].md(markdown) : // then use it\n      console.error(\"No markdown support\")  // both d['html-doc'] and d['html-md'] are false\n```\n\n```javascript\nvar detectionizr = require('detectionizr');\n// be sure to attach event handler before you use detect or you could end up with a race-condition\ntest.on(\"detect\", function(name, exist) {\n  if(name === \"ls\" \u0026\u0026 test.ls)\n    console.log(\"We can use ls on this computer!\");\n});\n// call detect with an array of commands you want to test for\ntest.detect([\"imagemagick\", \"ls\", \"punycode\"]);\n\nif(test.punycode)\n  console.log(\"We can use test.punycode\");\nif(test.imagemagick)\n  console.log(\"We can use test.imagemagick\");\n```\n\n## Documentation\n*I use command, system library and nodejs module interchangeably in this text.*\n\n**NOT TESTED ON WINDOWS**\n\ndetectionizr has 4 methods:\n+ **require** ({String}) - works like the normal require, except false is returned if the module can not be found\n+ **detect** ({Array}) - takes a list of command names to test and *grows* your detectionizr variable with references to the commands. Note, that command line commands will not be available right away. See below.\n+ **on** ({String}, {Function}, [{Object}]) - If a command is not a node module, then the test run asynchronously, and you have to attach an event listener. In the current version, \"detect\" and \"finally\" is accepted as event name. The second argument is your callback function and the third (optional) the scope you want your callback to run in.\nThe listener will be called with 2 arguments, the name {String} and if it could be found {Boolean}. Multiple event listeners can be attached. All \"detect\" listeners are called for each package you are testing.\n+ **overwrite** ({String}, {Function}, [{Object}]) - The same as **on** but will delete all previous attached \"detect\" listeners.\n\n### Eat your own dog food\ndetectionizr uses ```child_process``` from native nodejs modules and also checks in the same manner as it will test your library dependecies. That is why, detectionizr will always have a reference to ```child_process```.\n\n### Implementation\ndetectionizr will first try and ```require``` the commands. If that fails, it will search for the command as a process with: ```command -v [command name]``` and ```which``` and look for a return value. If you experience false positives, please file a bug in the [issue tracker](https://github.com/dotnetCarpenter/npm-detectionizr/issues). The command ```command``` should be available on all [POSIX](https://en.wikipedia.org/wiki/POSIX#POSIX-oriented_operating_systems) compliant systems (OS X, Linux, Unix ect.). ```which``` should be able to find libraries like g++ ect.\n\n## Examples\n```javascript\nvar test = require(\"detectionizr\");\nfunction PackageManager() {\n    this.available = [];\n}\nPackageManager.prototype.recieve = function(name, exist) {\n    if(exist) this.available.push(name)\n}\nvar pm = new PackageManager();\ntest.on(\"detect\", pm.recieve, pm);\ntest.on(\"finally\", function() {\n  console.dir(pm);    // { available: [ 'imagemagick', 'rdjpgcom' ] }\n  console.dir(test);  /* { child_process: \n                           { fork: [Function],\n                             _forkChild: [Function],\n                             exec: [Function],\n                             execFile: [Function],\n                             spawn: [Function] },\n                          require: [Function: r],\n                          detect: [Function],\n                          on: [Function],\n                          overwrite: [Function],\n                          rdjpgcom: true, \u003c- command line libraries can not be referenced\n                          imagemagick: \u003c- but nodejs modules are referenced\n                           { identify: { [Function] path: 'identify' },\n                             readMetadata: [Function],\n                             convert: { [Function] path: 'convert' },\n                             resize: [Function],\n                             crop: [Function],\n                             resizeArgs: [Function] },\n                          imgcheck: false }*/\n});\ntest.detect([\"rdjpgcom\", \"imagemagick\", \"imgcheck\"]);\n```\n\n```javascript\n// Instead of\nvar mongodb;\ntry {\n    mongodb = require( 'mongodb' );\n}\ncatch( e ) {\n    if ( e.code === 'MODULE_NOT_FOUND' ) {\n        // The module hasn't been found\n    }\n}\n\n// write\nif( !require('detectionizr').detect(['mongodb']).mongodb) )\n    // The module hasn't been found\n\n// or\nvar mongodb = require('detectionizr').detect(['mongodb'].mongodb;\nif(!mongodb)\n  // The module hasn't been found\n// if you need to do something with mongodb later\n```\n\n## TODO\n+ Implement dereferencing with ``delete`` http://nodejs.org/docs/latest/api/globals.html#globals_require_cache\n+ Better documentation...\n+ Better tests...\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test your code using [grunt](https://github.com/cowboy/grunt).\n**NOTE** - If you symlink detectionizr into a another folder, e.g. ```npm link [../path/to/detectionizr]```, detectionizr will not be able to find modules in that folder's node_modules directory. This is because nodejs require function only looks in the symlinked folder and not in the folder you are working in. See [issue #4757](https://github.com/joyent/node/issues/4757).\n\n## Release History\n+ 0.1.5 - For some reason the 0.1.4 release didn't remove `whereis` as a test program. This was what the 0.1.4 release was suppose to do. Sorry.\n+ 0.1.4 - Fixed false positives on ubuntu. Bug #1\n+ 0.1.3 - Added \"finally\" event and fixed various bugs. detectionizr is now chainable.\n+ 0.1.2 - ```.detect``` now return a reference to detectionizr. Enabling the one liner.\n+ 0.1.1 - Fix for event listeners not being called for nodejs modules.\n+ 0.1.0 - Initial release\n\n## License\nCreated by [dotnetCarpenter](https://www.google.com/search?q=dotnetCarpenter)\nLicensed under the [WTFPL](http://www.wtfpl.net/about/) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnetcarpenter%2Fnpm-detectionizr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotnetcarpenter%2Fnpm-detectionizr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnetcarpenter%2Fnpm-detectionizr/lists"}