{"_id":"@allnulled/url-command","_rev":"1-a5675a2cdcda294603718e9590c8c2c3","name":"@allnulled/url-command","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@allnulled/url-command","version":"1.0.0","keywords":[],"author":{"name":"allnulled"},"license":"WTFPL","_id":"@allnulled/url-command@1.0.0","maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"dist":{"shasum":"3b2e5dea2096588cd56fd1326b3a9681a6d7a913","tarball":"https://registry.npmjs.org/@allnulled/url-command/-/url-command-1.0.0.tgz","fileCount":4,"integrity":"sha512-kE2utrZdePWE6G7EBn7TKyEcXAth2h3xYQHc1mg8STyXdfkBYj/A2Xdc8d01hcHVMvu9ntnl5PbYXvqY3Y17Jg==","signatures":[{"sig":"MEQCIB/nLZXVMNdN/8HyoFymsnu1TPUNIJB3ZhkVGbfMjSdqAiATmDEqz4MIJOinv4pMMkSLWrRNfUC2omRZqZN2MbKnUQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":5154},"main":"url-command.js","gitHead":"9ed849e0355b026265947c7c17c83082c798343a","scripts":{"test":"npx universal-tester test.js"},"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"_npmVersion":"9.6.7","description":"Call functions through URL + Object.","directories":{},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/url-command_1.0.0_1737779001579_0.6958008507754001","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@allnulled/url-command","version":"1.0.1","description":"Call functions through URL + Object.","main":"url-command.js","scripts":{"test":"npx universal-tester test.js"},"keywords":[],"author":{"name":"allnulled"},"license":"WTFPL","gitHead":"817e160c794a660dab19356750bad2a4abc879e1","_id":"@allnulled/url-command@1.0.1","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-aTbhm4rM1nVVe3lFhjOeuHZ6LwneyrpA7IV9Uq4R+EO0MTwceU6/y80I85d/ujGMoDxgT72KDukgi8PMasHoTg==","shasum":"2c7b437ec392d989aaa5c43f96c2e14764d3bbab","tarball":"https://registry.npmjs.org/@allnulled/url-command/-/url-command-1.0.1.tgz","fileCount":4,"unpackedSize":6399,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDKUOYrJ7SonnWRvGJy7SguEe/S8fYYSRM2Tp6WaXr4ZAIhAIXhvhg/xx104L21cGUj0gnD+Kg3MzjT2ITktYyDD4MC"}]},"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"directories":{},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/url-command_1.0.1_1737780695934_0.05892721906713483"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-25T04:23:21.513Z","modified":"2025-01-25T04:51:36.251Z","1.0.0":"2025-01-25T04:23:21.743Z","1.0.1":"2025-01-25T04:51:36.090Z"},"author":{"name":"allnulled"},"license":"WTFPL","keywords":[],"description":"Call functions through URL + Object.","maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"readme":"# url-command\n\nUse URLs and Objects to call functions.\n\n## Install\n\n```sh\nnpm i -s url-command\n```\n\n## Import\n\nIn node.js:\n\n```js\nrequire(\"@allnulled/url-command\");\n```\n\nIn html:\n\n```html\n<script src=\"node_modules/@allnulled/url-command/url-command.js\"></script>\n```\n\n## API\n\n**1. Create an instance**\n\nUse `URLCommand.from(object)` to create an instance.\n\n**2. Run commands**\n\nThen use `urlcommand.run(text)` to run commands by URL.\n\nIt will call the function passing 1 object only, containing the parameters provided on `run`.\n\n**3. Run functions**\n\nYou can use the parameter `?...&argumentsOrder=a,b,c,d` to call functions using all the parameters allowed by JavaScript.\n\nIt will call the function spreading the specified properties in the specified order.\n\n**4. Pass data too**\n\nApart from the querystring parameters, you can pass data, like objects and functions and whatever (no strings, I mean), with a second parameter on the `run` method.\n\n\n\n\n\n## Usage\n\n```js\nconst object = {\n    command: {\n        hello({ name }): () => console.log(\"hello, \" + name)\n    }\n};\nURLCommand.from(object).run(\"/command/hello?name=world\");\n```\n\n## Test\n\n```js\nrequire(__dirname + \"/url-command.js\")\n\ndescribe(\"URLCommand API Test\", function (it) {\n  // Ejemplo de uso\n  const handlers = {\n    sum: ({ a, b }) => parseFloat(a) + parseFloat(b),\n    maths: {\n      multiply: ({ a, b }) => parseFloat(a) * parseFloat(b),\n      sumatory: (...args) => {\n        let out = 0;\n        for(let index=0; index<args.length; index++) {\n          const arg = args[index];\n          out += parseFloat(arg);\n        }\n        return out;\n      }\n    },\n    commands: {\n      hello: (urlParams) => {\n        const { name } = urlParams;\n        const msg = \"hello, \" + name;\n        return msg;\n      },\n      message(emitter, receiver, contents) {\n        const msg = `${emitter} says to ${receiver}: \"${contents}\"`;\n        return msg;\n      },\n      bye: (name) => {\n        const msg = \"bye, \" + name;\n        return msg;\n      },\n    }\n  };\n\n  const urls = [\n    [\"/commands/hello?name=world\", \"hello, world\"],\n    [\"/sum?a=10&b=2\", 12],\n    [\"/maths/multiply?a=10&b=2\", 20],\n    [\"/maths/sumatory?a=40&b=7&c=2&d=1&argumentsOrder=a,b,c,d\", 50],\n    [\"/commands/message?a=origin&b=destination&c=This is a request&argumentsOrder=a,b,c\", 'origin says to destination: \"This is a request\"'],\n    [\"/commands/bye?argumentsOrder=a\", 'bye, Emily', { a: \"Emily\" }],\n  ];\n\n  for (let index = 0; index < urls.length; index++) {\n    const [url, result, args = {}] = urls[index];\n    it(\"Can run: \" + url, function () {\n      const output = URLCommand.from(handlers).run(url, args);\n      ensure({ output }).is(result);\n    });\n  }\n});\n```","readmeFilename":"README.md"}