Socket
Socket
Sign inDemoInstall

koalas

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.1.1

.gitattributes

68

index.js

@@ -0,2 +1,68 @@

'use strict';
module.exports = require('./lib/koalas');
var slice = Array.prototype.slice;
var noop = function (value) {
return value;
};
var create = function (args) {
var obj = args[0];
args = args.splice(1);
function F() {
return obj.apply(this, args);
}
F.prototype = obj.prototype;
return new F();
};
var Koalas = function () {
this.args = slice.call(arguments);
this.funcs = [];
this.funcs.push(noop);
};
Koalas.prototype.use = function (func) {
this.funcs.push(func);
return this;
};
Koalas.prototype.process = function (value) {
var ret = value;
for (var i = 0; i < this.funcs.length; i++) {
ret = this.funcs[i](ret);
if (typeof ret === 'undefined' || ret === null) {
break;
}
}
return ret;
};
Koalas.prototype.value = function () {
var ret = null;
for (var i = 0; i < this.args.length; i++) {
var arg = this.process(this.args[i]);
if (typeof arg !== 'undefined' && arg !== null) {
ret = arg;
break;
}
}
return ret;
};
var koalas = module.exports = function () {
return create([Koalas].concat(slice.call(arguments)));
};
koalas.coalesce = function () {
var args = slice.call(arguments);
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if (typeof arg !== 'undefined' && arg !== null) {
return arg;
}
}
return null;
};

57

package.json
{
"name": "koalas",
"version": "0.0.6",
"description": "Koalas is a library for doing a coalesce in JavaScript",
"main": "index.js",
"scripts": {
"test": "grunt test"
"version": "0.1.1",
"description": "Coalesce for JavaScript",
"author": {
"name": "Brian Woodward",
"url": "https://github.com/doowb"
},
"bugs": {
"url": "https://github.com/doowb/koalas/issues"
},
"repository": {

@@ -13,23 +16,39 @@ "type": "git",

},
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
],
"main": "index.js",
"scripts": {
"test": "mocha -R spec"
},
"keywords": [
"chainable",
"check",
"isnull",
"kind",
"koala",
"koalas",
"koala",
"null",
"undefined"
"type",
"type-of",
"typeof",
"undefined",
"util",
"utility",
"utils",
"value"
],
"author": "Brian Woodward",
"license": "MIT",
"bugs": {
"url": "https://github.com/doowb/koalas/issues"
"devDependencies": {
"mocha": "*",
"should": "^4.0.4",
"verb": ">= 0.2.6",
"verb-tag-jscomments": ">= 0.2.0"
},
"devDependencies": {
"chai": "~1.8.1",
"grunt": "~0.4.2",
"mocha": "~1.16.2",
"grunt-mocha-test": "~0.8.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jshint": "~0.7.0",
"grunt-verb": "0.0.5"
"homepage": "https://github.com/doowb/koalas",
"engines": {
"node": ">=0.10.0"
}
}

@@ -1,33 +0,20 @@

# koalas [![NPM version](https://badge.fury.io/js/koalas.png)](http://badge.fury.io/js/koalas)
# koalas [![NPM version](https://badge.fury.io/js/koalas.svg)](http://badge.fury.io/js/koalas)
> Koalas is a library for doing a coalesce in JavaScript
## Getting Started
To install the module, run the following in the command line:
> Coalesce for JavaScript
## Install
#### Install with [npm](npmjs.org):
```bash
npm i koalas --save
npm i koalas --save-dev
```
Use within your application with the following line of JavaScript:
```js
var koalas = require('koalas');
```
## Usage Examples
#### Simple Example
#### Get the first non-null value
Given a list of values, find the first one that isn't null or undefined.
```js
var value = koalas.coalesce('foo', 'bar', 'baz', null, undefined);
```
#### Simple Example 2
Use something similar to lodash by passing your arguments directly into
Or, use something similar to lodash by passing your arguments directly into
koalas and calling `value()` to get the first non null/undefined value.

@@ -39,6 +26,5 @@

#### Simple Example 3 - Array Argument
#### Array Argument
Sometimes you want to use an array instead of passing all the arguments
in.
Sometimes you want to use an array instead of passing all the arguments in.

@@ -51,3 +37,3 @@ ```js

#### Use Method Example
#### `.use()`

@@ -69,3 +55,3 @@ With the `use` method, pass in functions that will evaluate can evaluate

#### Find Valid Path Example
#### Get the first valid file path

@@ -86,6 +72,5 @@ This example returns the first path that exists.

#### Complex Example 1
#### Object with specified property
Find the first object that contains a specific property that is non
null/undefined.
Find the first object that contains a specific property that is not null/undefined.

@@ -109,6 +94,5 @@ ```js

#### Complex Example 2
#### Object with method
Find the first object that contains a method that returns a valid non
null/undefined value.
Find the first object that contains a method that returns a valid non null/undefined value.

@@ -132,24 +116,15 @@ ```js

## Contributing
Find a bug? Have a feature request? Please [create an Issue](https://github.com/doowb/koalas/issues).
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality,
and run `docs` in the command line to build the docs with [Verb](https://github.com/assemble/verb).
Pull requests are also encouraged, and if you find this project useful please consider "starring" it to show your support! Thanks!
## Author
**Brian Woodward**
+ [github/doowb](https://github.com/doowb)
+ [twitter/doowb](http://twitter.com/jonschlinkert)
+ [twitter/doowb](http://twitter.com/doowb)
## License
Copyright (c) 2014 Brian Woodward, contributors.
Released under the MIT license
***
_This file was generated by [grunt-verb](https://github.com/assemble/grunt-verb) on March 26, 2014._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 29, 2014._
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