{"_id":"z-builtins","_rev":"8-0b6491de882d4776a6ff4f26dd9fe6b9","name":"z-builtins","description":"JavaScript builtin mixins for Z","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.1":{"name":"z-builtins","description":"JavaScript builtin mixins for Z","keywords":["promises","util","functional","server","client","browser"],"version":"0.1.1","author":{"name":"Jakob Mattsson","email":"jakob.mattsson@gmail.com","url":"jakobmattsson.se"},"license":"MIT","main":"./lib/index.js","repository":{"type":"git","url":"http://github.com/jakobmattsson/z-builtins"},"bugs":{"url":"http://github.com/jakobmattsson/z-builtins/issues"},"files":["lib","LICENSE"],"engines":{"npm":">= 1.3 < 2","node":">= 0.10 < 0.11"},"devDependencies":{"z-core":"^0.4.1","jscov":"^0.5.7","mocha":"^1.12.1","mocha-term-cov-reporter":"^0.2.0","chai-as-promised":"^4.1.0","mocha-as-promised":"^2.0.0","coffee-script":"^1.7.1"},"dependencies":{},"scripts":{"build":"rm -rf lib && coffee -co lib src","make-dist":"npm test && mkdir -p dist && browserify lib/index.js > dist/latest.js","coverage":"jscov --expand --conditionals src .cov && JSCOV=.cov mocha --reporter mocha-term-cov-reporter","test":"mocha --grep \"$TESTS\"","pretest":"npm run build","prepublish":"npm run build"},"homepage":"https://github.com/jakobmattsson/z-builtins","_id":"z-builtins@0.1.1","dist":{"shasum":"d5866073970d474cb3d011b7de658ab90bfe979f","tarball":"https://registry.npmjs.org/z-builtins/-/z-builtins-0.1.1.tgz","integrity":"sha512-N/zQl/myx8AhDiNown/xUQPTF8uLgvTJpLS8I67F+pWXtk0KutNtYc6vB+jhSMjsWjrHaniHM13dlpKZqRZIiA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID0pOUwcCcNU9CUGcu38NePIleyWbO4UEsJHWjEp882NAiAnHcCg+hMNKIL0W2W57bGWcybGDSvfCRN+hf8++aKjug=="}]},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"jakobm","email":"jakob.mattsson@gmail.com"},"maintainers":[{"name":"jakobm","email":"jakob.mattsson@gmail.com"}]},"0.1.2":{"name":"z-builtins","description":"JavaScript builtin mixins for Z","keywords":["promises","util","functional","server","client","browser"],"version":"0.1.2","author":{"name":"Jakob Mattsson","email":"jakob.mattsson@gmail.com","url":"jakobmattsson.se"},"license":"MIT","main":"./lib/index.js","repository":{"type":"git","url":"http://github.com/jakobmattsson/z-builtins"},"bugs":{"url":"http://github.com/jakobmattsson/z-builtins/issues"},"files":["lib","LICENSE"],"engines":{"npm":">= 1.3 < 2","node":">= 0.10 < 0.11"},"devDependencies":{"z-core":"^0.4.1","jscov":"^0.5.7","mocha":"^1.12.1","mocha-term-cov-reporter":"^0.2.0","chai-as-promised":"^4.1.0","mocha-as-promised":"^2.0.0","coffee-script":"^1.7.1"},"dependencies":{},"scripts":{"build":"rm -rf lib && coffee -co lib src","make-dist":"npm test && mkdir -p dist && browserify lib/index.js > dist/latest.js","coverage":"jscov --expand --conditionals src .cov && JSCOV=.cov mocha --reporter mocha-term-cov-reporter","test":"mocha --grep \"$TESTS\"","pretest":"npm run build","prepublish":"npm run build"},"homepage":"https://github.com/jakobmattsson/z-builtins","_id":"z-builtins@0.1.2","dist":{"shasum":"79d3bd0bcc344b9a8877e023ac3e42dc5c902c57","tarball":"https://registry.npmjs.org/z-builtins/-/z-builtins-0.1.2.tgz","integrity":"sha512-7MXobBsdBmHWnRFcGXcPD/NVj8oahGBxC0BAFSVTeUDAggJ1IwiZJOq8VLlcTlrPdJXk8km5iyychTBFy7LbFA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDSD9G1VZmX5lNVzyUURHqm9nEoejDMYr+uzUzivlHYnAIhAPpFGMzvvmCMXucvjXbUVnMk+Dd1/wChaUHwvni+sEUt"}]},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"jakobm","email":"jakob.mattsson@gmail.com"},"maintainers":[{"name":"jakobm","email":"jakob.mattsson@gmail.com"}]},"0.2.1":{"name":"z-builtins","description":"JavaScript builtin mixins for Z","keywords":["promises","util","functional","server","client","browser"],"version":"0.2.1","author":{"name":"Jakob Mattsson","email":"jakob.mattsson@gmail.com","url":"jakobmattsson.se"},"license":"MIT","main":"./lib/index.js","repository":{"type":"git","url":"http://github.com/jakobmattsson/z-builtins"},"bugs":{"url":"http://github.com/jakobmattsson/z-builtins/issues"},"files":["lib","LICENSE"],"bucketful":{"bucket":"z-builtins.jdevab.com","source":"tmp/browsertest","region":"eu-west-1"},"chalcogen":{"timeout":60000,"domain":"z-builtins.jdevab.com.s3-website-eu-west-1.amazonaws.com","path":"/default/index.html","environments":[{"browserName":"internet explorer","platform":"Windows 8","version":"10"},{"browserName":"firefox","platform":"Windows 8","version":"26"},{"browserName":"chrome","platform":"Linux","version":"26"},{"browserName":"chrome","platform":"Windows 8.1","version":"beta"},{"browserName":"chrome","platform":"OS X 10.8","version":"beta"},{"browserName":"safari","platform":"OS X 10.8","version":"6"},{"browserName":"safari","platform":"Windows 7","version":"5"}]},"engines":{"npm":">= 1.3 < 2","node":">= 0.10 < 0.11"},"devDependencies":{"z-core":"^0.5.5","jsontool":"7.0.1","commonjs-everywhere":"^0.9.7","bucketful":"^0.15.1","chalcogen":"^0.4.0","jscov":"^0.5.7","mocha":"^1.18.0","mocha-term-cov-reporter":"^0.2.0","chai-as-promised":"^3.3.1","coffee-script":"^1.7.1"},"dependencies":{},"scripts":{"test":"make run-tests"},"homepage":"https://github.com/jakobmattsson/z-builtins","_id":"z-builtins@0.2.1","dist":{"shasum":"e49430a3a23d1f1276e9b283185eda61271db1f2","tarball":"https://registry.npmjs.org/z-builtins/-/z-builtins-0.2.1.tgz","integrity":"sha512-W6vn68hKhG4LjAlFJ2Y+CC5lOuGJ7lBzZH4yZ9tL7oCzUqnQE5fCrFxNU982vfmLxGUku8wu5jnd9Ah2DjwWzA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGRQCfZ+mzEHzWXDaS8bo7085lqxFym2OSo7L7QCUtpRAiAilduMXCu+v8s2SVPccT1a37uE9w2k43x/seoLn6oJ8A=="}]},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"jakobm","email":"jakob.mattsson@gmail.com"},"maintainers":[{"name":"jakobm","email":"jakob.mattsson@gmail.com"}]}},"readme":"# z-builtins [![Build Status](https://secure.travis-ci.org/jakobmattsson/z-builtins.png)](http://travis-ci.org/jakobmattsson/z-builtins)\n\nA plugin for [Z](https://github.com/jakobmattsson/z-core), the utility library for JavaScript promises.\n\nThe z-builtins plugin exposes all native JavaScript methods directly on Z promises.\n\n\n\n## Installation\n\nThe easiest way to get started is to use a ready-made package of Z, like [z-std-pack](https://github.com/jakobmattsson/z-core). It includes this plugin.\n\n---\n\nIf you want to set it up yourself, you have a number of options:\n\n* `npm install z-builtins` and then `var zBuiltins = require('z-builtins');`\n\n* `bower install z-builtins`\n\n* Download it manually from the dist folder of this repo.\n\nWhen installed, you apply the plugin by calling `Z.mixin(zBuiltins)`. Note that you have to install [Z](https://github.com/jakobmattsson/z-core) first, if you're not using a ready-made package.\n\n\n\n## Crash course\n\nGo to the [Z main page](https://github.com/jakobmattsson/z-core) to learn what Z does.\n\nThe idea behind this particular plugin, **z-builtins**, is to expose all the standard JavaScript methods available on strings, arrays and other types of objects directly on promises wrapping them. It allows you to do things like:\n\n```js\n// Let's assume this returns a Z-promise.\n// If it expects a callback then we can convert it using Z beforehand.\nvar people = getJSON('/people');\n\n// Even though \"people\" is a promise, and not an array,\n// we can now use all the regular methods as if it was an array.\n// No need to sprinke our code with \".then\".\nvar listOfToddlers = people.filter(function(person) {\n  return person.age <= 3;\n}).map(function(person) {\n  return person.name;\n}).join('\\n');\n\n// Even global methods like \"console.log\" are\n// available directly on our objects now.\nlistOfToddlers.log();\n```\n\nAll the usual methods are available directly on promises. Instead of returning their results directly (which would be impossible, since the promise might not have resolved) they in turn return new promises. Those new promises also have all the expected methods. And so on. Down to turtles.\n\nThe only time you have to treat these objects diferently then you have treated regular objects is when you call global functions like `console.log`. If the list of toddlers from above was used like this, then `console.log(listOfToddlers)` would just print `\"[object Object]\"` since  `listOfToddlers` is not actually as string; it's a promise. Instead, either do `listOfToddlers.then(function(list) { console.log(list)); };` or simply `listOfToddlers.log()`.\n\n\n## Methods included in this plugin\n\nExcept then explicitly noted, all methods below will invoke their [native counterparts](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects) directly. All quirks and bugs will still get to you. As will all fixes and performance improvements in the future.\n\n\n\n### String methods\n\n```js\ncharAt\ncharCodeAt\nconcat\nindexOf\nlastIndexOf\nlocaleCompare\nreplace\nsearch\nslice\nsplit\nsubstr\nsubstring\ntoLocaleLowerCase\ntoLocaleUpperCase\ntoLowerCase\ntoString *AND* toStr\ntoUpperCase\ntrim\n```\n\nNote that `toString` has not been overridden to return a promise. It will return a string as always. That is to follow the principle of least surprise. If you want to call `toString` on the value that the promise resolves to, then you can use `toStr`.\n\n##### Example:\n\n```js\nvar html = getHTML('http://www.google.com');\n\nvar str1 = html.toString(); // An actual string, containing \"[object Object]\"\n\nvar str2 = html.toStr();    // A promise, containing the html-string\n\nconsole.log(str1);          // The actual string can be used in all the ways strings can\n\nstr2.then(function(s) {     // The promised string has to be resolved\n  console.log(s);           // \"<html><head>......\"\n});\n\nstr2.slice(0, 5).log();     // Or better, used with methods from this plugin.\n                            // Prints \"<html\"\n\n```\n\n\n### Array methods\n\n\n```js\npop *\npush *\nreverse *\nshift *\nsort *\nsplice *\nunshift *\nconcat\njoin\nslice\ntoString *AND* toStr // same as String.toString, earlier in the docs\ntoLocaleString\nindexOf\nlastIndexOf\nforEach\nevery\nsome\nfilter\nmap\nreduce\nreduceRight\n```\n\nThe methods followed by a star are mutator methods in the JavaScript standard library. They change the object they act upon and return something else.\n\nMutating behaviour doesn't work well with promises. Therefore, these methods do **not** mutate when used in Z. Their usual return values are ignored and instead they return the new array produced.\n\n##### Example:\n\n```js\nvar numbers = getJSON('/primeNumbers?n=5');\n\nnumbers.log(); // 2, 3, 5, 7, 11\n\nvar newNumbers = numbers.push(9000);\n\nnumbers.log(); // still 2, 3, 5, 7, 11\nnewNumbers.log(); // 2, 3, 5, 7, 11, 9000\n```\n\n\n### JSON methods\n\n```\nparseJSON (alias for JSON.parse, since parse is ambiguous)\nstringify\n```\n\n\n\n### Math methods\n\n```\nabs\nacos\nasin\natan\natan2\nceil\ncos\nexp\nfloor\nlogarithm (alias for log, since log is for console.log)\nmax\nmin\npow\nround\nsin\nsqrt\ntan\n```\n\n\n\n### Number methods\n\n```\ntoExponential\ntoFixed\ntoLocaleString\ntoPrecision\n```\n\n\n\n### Regexp methods\n\n```\nexec\ntest\n```\n\n\n\n### Function methods\n\n```\napply\nbind\ncall\n```\n\n\n\n### Operators\n\n```\nget - the dot and indexing operators (. and [])\ninc - increment (++)\ndec - decrement (--)\nneg - negate (-)\ntypeof\ndel - delete\nin\ninstanceof\nmult - multiplication (*)\ndiv - division (/)\nmod - modulo (%)\nadd - addition (+)\nsub - subtraction (-)\nbitNot - bitwise not (~)\nbitAnd - bitwise and (&)\nbitOr - bitwise or (|)\nbitLeft - bitwise left shift (<<)\nbitRight - bitwise right shift (>>)\nbitRightFill - bitwise right shift zero fill (>>>)\ngt - greater than (>)\ngte - greather than or equal to (>=)\nlt - less than (<)\nlte - less than or equal to (<=)\nand - logical and (&&)\nor - logical or (||)\nnot - logical not (!)\nif - the conditional operator (:?)\n```\n\nNote: The operators `yield`, `void`, `new`, `,` and the assignment operators are not available.\n\n\n\n### Global functions\n\n```\neval\nisFinite\nisNaN\nparseFloat\nparseInt\ndecodeURI\ndecodeURIComponent\nencodeURI\nencodeURIComponent\nescape\nunescape\n```\n\nThese functions use the promised value as their first argument. Remaining arguments can be given as usual.\n\n##### Example\n\n```js\nZ(\"1+5\").eval().log(); // 6\nZ(\"1111\").parseInt(2); // 15\n```\n\n\n\n### Other methods\n\n```js\nlength\nisArray\nlog\nprint\n```\n\nThe `length` method returns the value of the length property.\n\nThe `isArray` method invokes `Array.iArray`.\n\nThe `log` method invoked `console.log`.\n\nThe `print` method invokes `JSON.stringify` followed by `console.log`.\n\n\n\n##### Example:\n\n```js\nvar people = getJSON('/people');\n\npeople.isArray().log(); // true\n\npeople.length().log(); // 6000000000\n```\n","maintainers":[{"name":"jakobm","email":"jakob.mattsson@gmail.com"}],"time":{"modified":"2022-06-29T08:44:05.802Z","created":"2014-02-22T16:03:35.312Z","0.1.1":"2014-02-22T16:03:35.312Z","0.1.2":"2014-02-25T15:43:46.229Z","0.2.1":"2014-03-18T21:52:09.347Z"},"readmeFilename":"README.md","homepage":"https://github.com/jakobmattsson/z-builtins","keywords":["promises","util","functional","server","client","browser"],"repository":{"type":"git","url":"http://github.com/jakobmattsson/z-builtins"},"author":{"name":"Jakob Mattsson","email":"jakob.mattsson@gmail.com","url":"jakobmattsson.se"},"bugs":{"url":"http://github.com/jakobmattsson/z-builtins/issues"},"license":"MIT"}