Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arguejs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arguejs - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

9

argue.js

@@ -73,2 +73,4 @@ !function (name, context, definition) {

var type = (optional) ? signature[name][0] : signature[name];
if(type === undefined)
throw new TypeError("unsupported parameter type "+type);

@@ -197,3 +199,3 @@ var copy = expansion.slice(0);

if(type === undefined)
//workaround for the PhantomJS, to avoid DOMWindow casting.
//workaround for the PhantomJS to avoid DOMWindow casting.
//see more at http://stackoverflow.com/q/14218670/599991

@@ -213,3 +215,5 @@ return "Undefined";

if (type == Function
if(type === null || type === undefined)
return value === type;
else if (type == Function
&& typeof (/./) !== 'function') // Hack needed, as seen on UnderscoreJS' `isFunction`, reasons unknown

@@ -239,3 +243,2 @@ result = typeof value === 'function';

// Relinquish ArgueJS's control of the __ variable.
throw new Error("noConflit is not implemented for module loaders");

@@ -242,0 +245,0 @@ }

@@ -0,2 +1,5 @@

## v0.2.1
* Fix on `belongs` when dealing with `undefined` and `null` values
## v0.2.0

@@ -3,0 +6,0 @@

{
"name": "arguejs",
"version": "0.2.0",
"version": "0.2.1",
"description": "ArgueJS is a library that allows you to delightfully extend your methods's signatures with optional parameters, default values and type-checking.",

@@ -5,0 +5,0 @@ "main": "argue.js",

@@ -147,2 +147,4 @@ <p align="center">

The relation of ArgueJS with `undefined` and `null` values is detail explained at our Wiki page [Null and Undefined types](https://github.com/zvictor/ArgueJS/wiki/Null-and-Undefined-types)
## Optional parameters

@@ -196,17 +198,66 @@

-------------------------------
## Utilities
Some JavaScript methods [do not work intuitively](http://webreflection.blogspot.com.br/2012/06/javascript-typeof-operator-problem.html)
when dealing with types. This is why we made available these utilities methods, to help you to better deal with them.
### typeof
Util function that gives us the String representation of the type of a given object.
Consider the following example, using the native `typeof` method:
```javascript
> function whichType() {
return typeof this;
}
> [
whichType.call(false), // "boolean", right? No!
whichType.call("hello"), // "string", right? No!
whichType.call(123), // "number", right? No!
];
[ 'object', 'object', 'object' ]
```
Replace the function `whichType` to use ArgueJS' `__.typeof` and you will have the expected values:
```javascript
function whichType() {
return __.typeof( this );
}
```
```javascript
[ 'Boolean', 'String', 'Number' ]
```
### getType
The method `__.getType` gives us the type class of the object we may want to inspect.
Why using String representations when we can access the type directly?
### typeof
```javascript
Util function that gives us the String representation of the type of the given object.
> __.getType({key:"value"}) === Object
true
> constructor = __.getType(7)
[Function: Number]
> constructor("myString") // Number("myString")
NaN
> __.getType(this)
[Function: global]
```
### belongs
Util function that determines if a given instance belongs to the given type class.
The method `__.belongs` tells us if a given instance belongs to the given type class.
No excuses to compare String representations anymore!
```javascript
> __.belongs({key:"value"}, Object)
true
> __.belongs(this, __.type.global)
true
> __.belongs("value", Number)
false
```
### noConflict

@@ -218,2 +269,3 @@

var ArgueJS = __.noConflict();
// Now, __ makes reference to its old value, the one before you added ArgueJS
```

@@ -220,0 +272,0 @@ -------------------------------

@@ -16,9 +16,9 @@ define(['argue', 'chai'], function(__, chai) {

upper();
}).should.throw("unsupported type undefined");
}).should.throw("unsupported parameter type undefined");
(function(){
upper(undefined);
}).should.throw("unsupported type undefined");
}).should.throw("unsupported parameter type undefined");
(function(){
upper(null);
}).should.throw("unsupported type undefined");
}).should.throw("unsupported parameter type undefined");

@@ -25,0 +25,0 @@ });

@@ -59,9 +59,7 @@ define(['argue', 'chai'], function(__, chai) {

it('should not accept Null and Undefined types', function() {
//wrong:
(function(){
__.belongs(undefined, undefined)
}).should.throw("unsupported type undefined");
(function(){
__.belongs(null, null)
}).should.throw("unsupported type null");
//right:
expect(__.belongs(undefined, undefined)).to.be.true;
expect(__.belongs(null, undefined)).to.be.false;
expect(__.belongs(undefined, null)).to.be.false;
expect(__.belongs(null, null)).to.be.true;

@@ -68,0 +66,0 @@ });

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc