Socket
Socket
Sign inDemoInstall

z-core

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.1 to 0.5.4

lib/promise.js

18

package.json

@@ -12,3 +12,3 @@ {

],
"version": "0.5.1",
"version": "0.5.4",
"author": "Jakob Mattsson <jakob.mattsson@gmail.com> (jakobmattsson.se)",

@@ -38,7 +38,2 @@ "license": "MIT",

"browserName": "internet explorer",
"platform": "Windows 7",
"version": "9"
},
{
"browserName": "internet explorer",
"platform": "Windows 8",

@@ -69,2 +64,4 @@ "version": "10"

"devDependencies": {
"commonjs-everywhere": "^0.9.7",
"es5-shim": "^2.3.0",
"browserify": "^3.30.2",

@@ -85,11 +82,4 @@ "bucketful": "^0.15.1",

"scripts": {
"make-dist": "npm test && mkdir -p dist && browserify lib/index.js > dist/latest.js",
"prepare-browser-tests": "sh scripts/prepare-browser-tests.sh",
"deploy-browser-tests": "npm run prepare-browser-tests && bucketful",
"test-browser-remote": "npm run deploy-browser-tests && chalcogen --platform saucelabs",
"coverage": "jscov --expand --conditionals src .cov && JSCOV=.cov mocha --reporter mocha-term-cov-reporter",
"test": "mocha --grep \"$TESTS\"",
"pretest": "coffee -co lib src",
"prepublish": "coffee -co lib src"
"test": "make run-tests"
}
}

@@ -6,5 +6,14 @@ # Z [![Build Status](https://secure.travis-ci.org/jakobmattsson/z-core.png)](http://travis-ci.org/jakobmattsson/z-core)

### Test status
[![Selenium Test Status](https://saucelabs.com/browser-matrix/jakobmattsson-zcore.svg)](https://saucelabs.com/u/jakobmattsson-zcore)
It's also been tested in Node.js 0.10 and 0.11.
### Installation
Use npm: `npm install z-core`
Use npm: `npm install z-core` and then `var Z = require('z-core');`

@@ -21,27 +30,30 @@ Or bower: (not uploaded yet)

var pmin = Z.bindSync(Math.min);
```js
var pmin = Z.bindSync(Math.min);
// It can still be called with regular values
pmin(10, 5).then(function(minValue) {
console.log(minValue); // 5
});
// It can still be called with regular values
pmin(10, 5).then(function(minValue) {
console.log(minValue); // 5
});
// But is can also be called with promises
var promise = returnsTheValue2AsPromise();
pmin(promise, 5).then(function(minValue) {
console.log(minValue); // 2
});
// But is can also be called with promises
var promise = returnsTheValue2AsPromise();
pmin(promise, 5).then(function(minValue) {
console.log(minValue); // 2
});
```
Use `bindAsync` to create promise-friendly functions from async functions.
var postPromisedJSON = Z.bindAsync(postJSON);
var agePromise = returnsTheValue28AsPromise();
```js
var postPromisedJSON = Z.bindAsync(postJSON);
var agePromise = returnsTheValue28AsPromise();
// Note that it's called with a mix of regular values an promises
postPromisedJSON('/people', { name: 'Jakob', age: agePromise }).then(function(res) {
console.log(res); // the result of the request
})
// Note that it's called with a mix of regular values an promises
postPromisedJSON('/people', { name: 'Jakob', age: agePromise }).then(function(res) {
console.log(res); // the result of the request
});
```
### Augmenting promises

@@ -51,25 +63,27 @@

Z.mixin({
get: function(prop) {
return this.value[prop];
},
toLowerCase: function() {
return this.value.toLowerCase();
},
first: function(n) {
if (n == null) {
n = 1;
}
return this.value.slice(0, n);
},
log: function() {
console.log(this.value);
}
});
```js
Z.mixin({
get: function(prop) {
return this.value[prop];
},
toLowerCase: function() {
return this.value.toLowerCase();
},
first: function(n) {
if (n == null) {
n = 1;
}
return this.value.slice(0, n);
},
log: function() {
console.log(this.value);
}
});
var getPromisedJSON = Z.bindAsync(getJSON);
var getPromisedJSON = Z.bindAsync(getJSON);
var firstThreeInName = getPromisedJSON('/cookies/123').get('name').toLowerCase().first(3);
var firstThreeInName = getPromisedJSON('/cookies/123').get('name').toLowerCase().first(3);
firstThreeInName.log();
firstThreeInName.log();
```

@@ -76,0 +90,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc