New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

n8iv

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

n8iv - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

# Array
## static methods
### from( value:Mixed ):Array
Returns an Array based on the passed `value`.
If the value is "Array like", e.g: a `HtmlCollection`, `NodeList` or Function `Arguments`, then an Array version will be returned.
Otherwise the `value` is wrapped in an Array and the Array is returned.
#### Example:
```html
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
</body>
```
```javascript
Array.from( document.body.children ); // returns => [div#one, div#two, div#three]
Array.from( document.body.querySelectorAll( '*' ) ); // returns => [div#one, div#two, div#three]
Array.from( function( a, b, c ) { return arguments; }( 1, 2, 3 ) ); // returns => [1, 2, 3]
Array.from( { one : 1, two : 2, three : 3 } ); // returns => [{ one : 1, two : 2, three : 3 }]
```
## static properties

@@ -55,3 +22,3 @@

Array.from( document.body.children ).sortBy( 'data-pos', 'desc' ); // returns => [div#three, div#two, div#one]
Array.coerce( document.body.children ).sortBy( 'data-pos', 'desc' ); // returns => [div#three, div#two, div#one]

@@ -174,19 +141,2 @@ ```

### find( iterator:Function[, context:Object] ):Mixed
Returns the first item in the Array that returns a "truthy" value when executing the passed `iterator` function over the Array, or `null` if none is found.
#### Example:
```javascript
[1, 2, 3, 4].find( function( value ) { return value > 2; } ); // returns => 3
[1, 2, 3, 4].find( function( value, index ) { return value > 2 && index > 2; } ); // returns => 4
[1, 2, 3, 4].find( function( value ) { return value > 4; } ); // returns => null
```
**REMEMBER:** The ACTUAL item in the Array is returned, NOT the `iterator`'s return value.
### flatten( [depth:Number] ):Array

@@ -193,0 +143,0 @@ Returns a one dimensional copy of the Array. Alternatively, you can pass a `depth` parameter to limit how many levels to `flatten`.

@@ -5,21 +5,2 @@ # Function

### @get n8ivName:Array
Tries to return the name of a Function based on it's `name`, `displayName` and/ or examining the Function's `toString` method.
If a Function is mimicking another Function it will return the mimicked Function's `n8ivName`.
#### Example:
```javascript
function foo( a, b, c ) { ... }
foo.n8ivName // returns => "foo"
( function( a, b, c ) { ... } ).n8ivName // returns => "anonymous"
var = function bar( a, b, c ) { ... }.mimic( foo ).n8ivName // returns => "foo"
```
### @get params:Array

@@ -45,5 +26,5 @@ Returns an Array of the argument names in a Function declaration by examining the Function's `toString` method.

( function( foo ) { return foo; } ).attempt( null, true ); // returns => true
( function( foo ) { return foo; } ).attempt( null, true ); // returns => true
n8iv.type( ( function( foo ) { return bar; } ).attempt( null, true ) ); // returns => 'error'
m8.type( ( function( foo ) { return bar; } ).attempt( null, true ) ); // returns => 'error'

@@ -124,21 +105,2 @@ ```

### mimic( callback:Function[, name:String] ):Function
Makes the Function look like the passed `callback` Function. Handy for profiling & debugging.
#### Example:
```javascript
function foo() { ... }
var bar = function() { ... }.mimic( foo );
bar.toString() // returns => "function foo() { ... }"
bar.valueOf() // returns => foo()
bar.displayName == 'foo' // returns => true
```
### wrap( wrapper:Function ):Function

@@ -145,0 +107,0 @@ Wraps the Function in the passed `wrapper` Function, supplying the original Function as the first parameter to the `wrapper` Function.

@@ -1,429 +0,23 @@

# n8iv
# n8iv( NativeType1:Function[, NativeType2:Function, ..., NativeTypeN:Function] ):n8iv
n8iv itself wraps `m8.x`. It does exactly the same thing and returns itself – the n8iv global.
## static methods
## n8iv.x( NativeType:Function, extensions:Function ):n8iv
If you want to extend a Native Type immediately you can pass it to `n8iv.x`, along with a Function containing the `extensions` and `n8iv` will make it so.
### bless( namespace:String[, context:Object] ):Object
Creates an Object representation of the passed `namespace` String and returns it.
Unlike `m8.x.cache`, which takes a String name of the Native Type you wish to extend, `n8iv.x` takes the actual Type.
If a `context` Object is given, the Object tree created will be added to the `context` Object, otherwise it will be added to the global namespace.
### Example:
**NOTE:** If any existing Objects with the same name already exist, they will **NOT** be replaced and any child Objects will be appended to them.
#### Example:
```javascript
n8iv.bless( 'foo.bar' ); // creates => global.foo.bar
typeof Array.prototype.foo; // returns => "undefined"
// you can now do:
foo.bar.Something = function() {};
n8iv.x( Array, function( Type ) {
m8.def( Type.prototype, 'foo', m8.describe( 'bar', 'w' ) );
} );
n8iv.bless( 'foo.bar', n8iv ); // creates => global.n8iv.foo.bar
typeof Array.prototype.foo; // returns => "string"
var bar = n8iv.bless( 'foo.bar' );
Array.prototype.foo == 'bar'; // returns => true
bar === foo.bar // returns => true
```
### bool( value:Mixed ):Boolean
Handy for working with Booleans trapped in Strings.
Returns a normalised Boolean value for a String, Number, null or undefined.
Everything will return `true`, except for the following:
```javascript
n8iv.bool( 'false' ); n8iv.bool( false );
n8iv.bool( '0' ); n8iv.bool( 0 );
n8iv.bool( 'NaN' ); n8iv.bool( NaN );
n8iv.bool( 'null' ); n8iv.bool( null );
n8iv.bool( 'undefined' ); n8iv.bool( undefined );
n8iv.bool(); n8iv.bool( '' );
```
### coerce( item:Mixed ):Mixed
Attempts to coerce primitive values "trapped" in Strings, into their real types.
#### Example:
```javascript
n8iv.coerce( 'false' ); // returns false
n8iv.coerce( 'null' ); // returns null
n8iv.coerce( 'true' ); // returns true
n8iv.coerce( 'undefined' ); // returns undefined
n8iv.coerce( 'NaN' ); // returns NaN
n8iv.coerce( '1' ); // returns 1
n8iv.coerce( '12' ); // returns 12
n8iv.coerce( '123' ); // returns 123
n8iv.coerce( '123.4' ); // returns 123.4
n8iv.coerce( '123.45' ); // returns 123.45
n8iv.coerce( '123.456' ); // returns 123.456
```
### copy( destination:Object, source:Object ):Object
Copies the properties – accessible via `Object.keys` – from the `source` Object to the `destination` Object and returns the `destination` Object.
#### Example:
```javascript
var foo = { one : 1, two : 2, three : 3 },
bar = n8iv.copy( {}, foo );
Object.equalTo( foo, bar ); // returns => true
foo === bar // returns => false
```
### def( item:Mixed, name:String, config:Object[, overwrite:Boolean, debug:Boolean]] ):n8iv
Shortened version of [Object.defineProperty](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty) with some extra options.
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>item</td><td>The item to define a property on.</td></tr>
<tr><td>name</td><td>The name of the property you are defining.</td></tr>
<tr><td>config</td><td>The property descriptor for the new/ modified property.</td></tr>
<tr><td>overwrite</td><td>Whether or not to attempt overwriting the new property if it exists.</td></tr>
<tr><td>debug</td><td>Whether or not to throw an error if the property already exists.</td></tr>
</table>
The last two – optional – parameters are handy for extending JavaScript Natives without risking collisions with native implementations.
`n8iv.addAccessor` & `n8iv.addMethod` both call `n8iv.def` internally.
### describe( value:Mixed[, mode:Object|String] ):Object
When using [Object.defineProperty](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty) en masse, your property descriptors can really start to bulk out your codebase.
Using `n8iv.describe` in combination with `n8iv.modes` can significantly reduce the amount of superfluous code you need to write. Especially when working with verbose property names like: `configurable`, `enumerable` & `writeable`.
When `value` is an Object `n8iv.describe` assumes you are passing it a property descriptor you want to assign modes to.
#### Example:
```javascript
n8iv.describe( {
get : function() { ... },
set : function() { ... }
}, 'cw' );
/* returns => {
configurable : true,
enumerable : false,
get : function() { ... },
set : function() { ... },
writeable : true
} */
```
When `value` is anything but an Object, it is assigned to the `value` property of the property descriptor.
#### Example:
```javascript
n8iv.describe( function() { ... }, n8iv.modes.c );
/* returns => {
configurable : true,
enumerable : false,
value : function() { ... },
writeable : false
} */
```
See `n8iv.modes` below for a list of available property descriptors.
### description( object:Object, key:String ):Object
Shortened version of [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor).
### error( error:Error|String[, chuck:Boolean] ):void
Wraps `console.error` passing the `error` to it, for logging in the `console`. If `console.error` does not exist, it is not called.
If `chuck` is `true` then the passed `error` will also be `throw`n halting any script execution.
**NOTE:** If you want the `error` to be thrown then it is recommended you pass `n8iv.error` an instance of an [Error](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error), so that the Error console will display the correct line number for your `error`. Otherwise the `error` will appear to come from `n8iv.error`, which is not very helpful when debugging.
### got( object:Object, key:String ):Boolean
Returns `true` if `object` contains `key` based on the `in` operator.
```javascript
var foo = { one : 1, two : 2, three : 3 };
n8iv.got( foo, 'one' ); // returns => true
n8iv.got( foo, 'four' ); // returns => false
n8iv.got( foo, '__type__' ); // returns => true
```
### has( object:Object, key:String ):Boolean
Shortened version of `Object.prototype.hasOwnProperty.call`.
#### Example:
```javascript
var foo = { one : 1, two : 2, three : 3 };
n8iv.has( foo, 'one' ); // returns => true
n8iv.has( foo, 'four' ); // returns => false
n8iv.has( foo, '__type__' ); // returns => false
```
### id( item:Mixed[, prefix:String] ):String
Returns the `id` property of the passed item – item can be an Object, DOM Node, "JavaScript Class" instance – if one does not exist, an `id` is created on the item and its value is returned.
If a `prefix` is supplied then it is used as the prefix for the `id` – if not `anon__` is used – with an automatically incremented counter appended to the end.
#### Example:
```javascript
var foo = { id : 'foo' },
bar = { name : 'bar' },
yum = { nam : 'yum' };
n8iv.id( foo ); // returns => "foo"
n8iv.id( bar ); // returns => "anon__1000"
n8iv.id( yum, 'yum-' ); // returns => "yum-1001"
```
### isEmpty( value:Mixed ):Boolean
Returns `true` if the passed `value` is `undefined` or `null`, returns `false` otherwise.
#### Example:
```javascript
n8iv.isEmpty( undefined ); // returns => true
n8iv.isEmpty( null ); // returns => true
n8iv.isEmpty( 0 ); // returns => false
n8iv.isEmpty( 0 ); // returns => false
n8iv.isEmpty( {} ); // returns => false
```
### isFn( value:Mixed ):Boolean
Returns `true` if the passed `value` is a Function, returns `false` otherwise.
#### Example:
```javascript
n8iv.isFn( function() {} ); // returns => true
n8iv.isFn( {} ); // returns => false
```
### isNum( value:Mixed ):Boolean
Returns `true` if the passed `value` is a Number, returns `false` otherwise.
#### Example:
```javascript
n8iv.isNum( 0 ); // returns => true
n8iv.isNum( NaN ); // returns => false
```
### isObj( value:Mixed ):Boolean
Returns `true` if the passed `value` is an Object, returns `false` otherwise.
#### Example:
```javascript
n8iv.isObj( {} ); // returns => true
n8iv.isObj( [] ); // returns => false
```
### isStr( value:Mixed ):Boolean
Returns `true` if the passed `value` is a String, returns `false` otherwise.
#### Example:
```javascript
n8iv.isStr( '' ); // returns => true
n8iv.isStr( [] ); // returns => false
```
### isUndef( value:Mixed ):Boolean
Returns `true` if the passed `value` is a `undefined`, returns `false` otherwise.
#### Example:
```javascript
var foo, bar = 'bar';
n8iv.isUndef( foo ); // returns => true
n8iv.isUndef( bar ); // returns => false
```
### nativeType( item:Mixed ):String
Returns the native `type` of the passed item. For normalised types use `n8iv.type`.
**Note:** All types are **always** in lowercase.
#### Example:
```javascript
n8iv.nativeType( null ); // returns => "null"
n8iv.nativeType( undefined ); // returns => "undefined"
n8iv.nativeType( [] ); // returns => "array"
n8iv.nativeType( true ); // returns => "boolean"
n8iv.nativeType( new Date() ); // returns => "date"
n8iv.nativeType( function() {} ); // returns => "function"
n8iv.nativeType( 0 ); // returns => "number"
n8iv.nativeType( {} ); // returns => "object"
n8iv.nativeType( Object.create( null ) ); // returns => "object"
n8iv.nativeType( /.*/ ); // returns => "regexp"
n8iv.nativeType( '' ); // returns => "string"
n8iv.nativeType( document.createElement( 'div' ) ); // returns => "htmldivelement"
n8iv.nativeType( document.querySelectorAll( 'div' ) ); // returns => "htmlcollection" | "nodelist"
n8iv.nativeType( document.getElementsByTagName( 'div' ) ); // returns => "htmlcollection" | "nodelist"
n8iv.nativeType( global ); // returns => "global"
n8iv.nativeType( window ); // returns => "global" | "window"
```
### noop():void
An empty Function that returns nothing.
### obj( [props:Obejct] ):Object
Creates an empty Object using `Object.create( null )`, the Object has no constructor and executing `Object.getPrototypeOf` on the empty Object instance will return `null` rather than `Object.prototype`.
Optionally pass an Object whose properties you want copied to the empty Object instance.
### proto( item:Mixed ):Mixed
Shortened version of [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/getPrototypeOf).
### tostr( item:Mixed ):String
Shortened version of `Object.prototype.toString.call`.
### trace():n8iv
Wraps `console.trace` so that if it does not exist, it is not called.
### type( item:Mixed ):String
Returns the normalised `type` of the passed item.
**Note:** All types are **always** in lowercase.
#### Example:
```javascript
n8iv.type( null ); // returns => false
n8iv.type( undefined ); // returns => false
n8iv.type( [] ); // returns => "array"
n8iv.type( true ); // returns => "boolean"
n8iv.type( new Date() ); // returns => "date"
n8iv.type( function() {} ); // returns => "function"
n8iv.type( 0 ); // returns => "number"
n8iv.type( {} ); // returns => "object"
n8iv.type( Object.create( null ) ); // returns => "nullobject"
n8iv.type( /.*/ ); // returns => "regexp"
n8iv.type( '' ); // returns => "string"
n8iv.type( document.createElement( 'div' ) ); // returns => "htmlelement"
n8iv.type( document.querySelectorAll( 'div' ) ); // returns => "htmlcollection"
n8iv.type( document.getElementsByTagName( 'div' ) ); // returns => "htmlcollection"
n8iv.nativeType( global ); // returns => "global"
n8iv.nativeType( window ); // returns => "global"
```
## static properties
### modes:Object
See `n8iv.describe` above for more information on how to use `n8iv.modes` to create property descriptors compatible with `Object.defineProperty`.
#### Available modes are:
<table border="0" cellpadding="0" cellspacing="0">
<thead><tr><th>mode</th><th>configurable</th><th>enumerable</th><th>writeable</th></tr></thead>
<tbody>
<tr><td><strong>r</strong></td><td>false</td><td>false</td><td>false</td></tr>
<tr><td><strong>ce</strong></td><td>true</td><td>true</td><td>false</td></tr>
<tr><td><strong>cw</strong></td><td>true</td><td>false</td><td>true</td></tr>
<tr><td><strong>ew</strong></td><td>false</td><td>true</td><td>true</td></tr>
<tr><td><strong>cew</strong></td><td>true</td><td>true</td><td>true</td></tr>
<tbody>
</table>
**NOTE:** You can supply the characters for a specific mode in any order.

@@ -5,3 +5,3 @@ # Object

### aggregate( object:Object, value:Mixed, iterator:Function[, context:Object] ):Mixed
### Object.aggregate( object:Object, value:Mixed, iterator:Function[, context:Object] ):Mixed
This works similar to `Object.reduce` except that the initial value is passed in as the second parameter instead of the last; and an **optional** `context` Object can be supplied.

@@ -37,3 +37,3 @@

### clear( object:Object ):Object
### Object.clear( object:Object ):Object
Removes all the passed `object`'s properties accessible via `Object.keys` and returns it.

@@ -47,56 +47,11 @@

Object.len( foo ); // returns => 3
m8.len( foo ); // returns => 3
Object.clear( foo );
m8.clear( foo );
Object.len( foo ); // returns => 0
m8.len( foo ); // returns => 0
```
### clone( object:Object ):Object
Returns a copy of the passed `object`.
#### Example:
```javascript
var foo = { one : 1, two : 2, three : 3 },
bar = Object.clone( foo );
foo == bar // returns => false
foo === bar // returns => false
Object.equalTo( foo, bar ); // returns => true
```
### each( object:Object, iterator:Function[, context:Object] ):Object
Iterates over the passed `object`, executing the `iterator` Function once for each item in the Object.
If a `context` Object is passed, it is used as the `this` value for the `iterator` Function, otherwise the passed `object` will be used as the `context`.
The `iterator` Function will receive 4 arguments:
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>value</td><td>The value of the item currently being iterated over.</td></tr>
<tr><td>key</td><td>The key of the item currently being iterated over.</td></tr>
<tr><td>object</td><td>The Object being iterated over.</td></tr>
<tr><td>index</td><td>The zero based index of the item currently being iterated over.</td></tr>
</table>
#### Example:
```javascript
Object.each( { one : 1, two : 2, three : 3 }, function( value, key, index, object ) {
console.log( 'value : ', value, ', key : ', key, ', index : ', index, ', object : ', object );
} );
// logs => value : 1, key : one, index : 0, object : { one : 1, two : 2, three : 3 }
// logs => value : 2, key : two, index : 1, object : { one : 1, two : 2, three : 3 }
// logs => value : 3, key : three, index : 2, object : { one : 1, two : 2, three : 3 }
```
### equalTo( object1:Object, object2:Object ):Boolean
### Object.equalTo( object1:Object, object2:Object ):Boolean
Returns `true` if both Objects' key/ value pairs are equal, `false` otherwise.

@@ -119,36 +74,3 @@

### key( object:Object, value:Mixed ):Null|String
Returns the `object`'s property `key` for the passed `value` if `value` is a property of `object`. If not `null` is returned.
**NOTE:** `value` is determined based on the `===` operator.
#### Example:
```javascript
var foo = { one : 1, two : 2, three : 3 };
Object.key( foo, 2 ); // returns => "two"
Object.key( foo, 4 ); // returns => null
```
### len( object:Object ):Number
Returns the `length` property of the Array returned when executing `Object.keys` on the passed Object.
#### Example:
```javascript
Object.len( { one : 1, two : 2, three : 3 } ); // returns => 3
Object.len( [1, 2, 3] ); // returns => 3
Object.len( { one : 1, two : 2, three : 3 } ) === Object.keys( { one : 1, two : 2, three : 3 } ).length
// returns => true
```
### ownKeys( object:Object ):String[]
### Object.ownKeys( object:Object ):String[]
Shortened version of [Object.getOwnPropertyNames](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames).

@@ -168,3 +90,3 @@

### ownLen( object:Object ):Number
### Object.ownLen( object:Object ):Number
Returns the `length` property of the Array returned when executing `Object.ownKeys` on the passed Object.

@@ -180,3 +102,3 @@

Object.len( [1, 2 ,3] ); // returns => 3
m8.len( [1, 2 ,3] ); // returns => 3

@@ -188,130 +110,4 @@ Object.ownLen( [1, 2, 3] ) === Object.getOwnPropertyNames( [1, 2, 3] ).length

### reduce( object:Object, iterator:Function, value:Mixed ):Mixed
This is similar to [Array.reduce](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce) except that it is used on Objects instead of Arrays.
---------------------------------------
The `iterator` Function will receive 5 arguments:
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>previous_value</td><td>When the <code>iterator</code> Function is first called, this will be the initially supplied <code>value</code>, after which it will be previous value returned by the <code>iterator</code> Function.</td></tr>
<tr><td>value</td><td>The value of the item currently being iterated over.</td></tr>
<tr><td>key</td><td>The key of the item currently being iterated over.</td></tr>
<tr><td>object</td><td>The Object being iterated over.</td></tr>
<tr><td>index</td><td>The zero based index of the item currently being iterated over.</td></tr>
</table>
#### Example:
```javascript
// the sum of all values of the passed object
Object.reduce( { one : 1, two : 2, three : 3 }, function( previous_value, value, key, index, object ) {
console.log( 'previous_value : ', previous_value, ', value : ', value, ', key : ', key, ', index : ', index );
return previous_value += value;
}, 0 );
// logs => previous_value : 0, value : 1, key : one, index : 0
// logs => previous_value : 1, value : 2, key : two, index : 1
// logs => previous_value : 3, value : 3, key : three, index : 2
// returns => 6
```
### remove( object:Object, key1:String[, key2:String, ..., key3:String] ):Object
Removes each `key` from the passed `object` and returns `object`.
#### Example:
```javascript
var foo = { one : 1, two : 2, three : 3 };
Object.remove( foo, 'one', 'three' ); // returns => { two : 2 }
Object.remove( foo, ['one', 'three'] ); // same as above
```
### value( object:Object, path:String ):Mixed
Returns the property value at the specified path in an Object.
#### Example:
```javascript
var data = { one : { two : { three : true, four : [1, 2, 3, 4] } } };
Object.value( data, 'one' ); // returns => { two : { three : true, four : [1, 2, 3, 4] } }
Object.value( data, 'one.two' ); // returns => { three : true, four : [1, 2, 3, 4] }
Object.value( data, 'one.two.three' ); // returns => { three : true }
Object.value( data, 'one.two.four' ); // returns => [1, 2, 3, 4]
Object.value( data, 'one.two.four.2' ); // returns => 3
```
### values( object:Object ):Array
Returns the `values` of the passed Object.
#### Example:
```javascript
Object.values( { one : 1, two : 2, three : 3 } ); // returns => [1,2,3]
```
---------------------------------------
**NOTE:** The reason why other iterators like `map` are not included, is that they can be achieved using `Object.reduce` and/ or `Object.aggregate`. So to reduce file size they have been ommited.
---------------------------------------
## OMFG!!! extensions to Object.prototype
As mentioned previously, n8iv extends JavaScript Natives correctly, so you don't need to worry about having a bunch of enumerable properties/ methods on any of instances of a native JavaScript object.
There are no instance methods just one convenience getter.
### \_\_type\_\_:String
Returns a normalised type based on the result of executing `Object.prototype.toString.call` on the `context` Object.
**Note:** All types are **always** in lowercase.
#### Examples:
```javascript
( null ).__type__; // throws => TypeError
( undefined ).__type__; // throws => TypeError
[].__type__; // returns => "array"
( true ).__type__; // returns => "boolean"
( new Date() ).__type__; // returns => "date"
( function() {} ).__type__; // returns => "function"
( 0 ).__type__; // returns => "number"
( {} ).__type__; // returns => "object"
Object.create( null ).__type__; // returns => undefined
( /.*/ ).__type__; // returns => "regexp"
( '' ).__type__; // returns => "string"
document.createElement( 'div' ).__type__; // returns => "htmlelement"
document.querySelectorAll( 'div' ).__type__; // returns => "htmlcollection"
document.getElementsByTagName( 'div' ).__type__; // returns => "htmlcollection"
```
**NOTE:** you can define your own custom `__type__` property on any `Function.prototype` you create so all instances of your "JavaScript Class" will return their custom type.
This is handled automatically when using n8iv.Class to create a "JavaScript Class".

@@ -37,5 +37,2 @@ # String

### cc():String
Alias for `toCamelCase`.
### clean( [character:String] ):String

@@ -167,13 +164,2 @@ Returns a "clean" copy of the String with all duplicate characters removed. The most common example is removing multiple space characters from a String.

### lc():String
Alias for `toLowerCase`.
#### Example:
```javascript
'LOREM IPSUM DOLOR'.lc() // returns => "lorem ipsum dolor"
```
### parts( re:RegExp ):String[]

@@ -192,13 +178,2 @@ Returns an Array of the **matched** parts of the resulting RegExp or an empty Array if there are no matches.

### qw():Array
Shorthand for splitting a String using `.split( ' ' );`.
#### Example:
```javascript
'one two three'.qw() // returns => ["one", "two", "three"]
```
### regexpEsc():String

@@ -343,13 +318,2 @@ Returns a RegExp escaped version of the String.

### uc():String
Alias for `toUpperCase`.
#### Example:
```javascript
'lorem ipsum dolor'.uc() // returns => "LOREM IPSUM DOLOR"
```
### underscore():String

@@ -356,0 +320,0 @@ Returns a copy of the String with any spaces and/ or hyphens replaced by underscores.

@@ -1,675 +0,311 @@

!function(_root) {
!function(m8) {
"use strict";
var n8iv = function(root) {
typeof root != "undefined" || (root = _root);
function $A(a, i, j) {
return got(a, "length") ? slice.call(a, isNum(i) ? i > 0 ? i : 0 : 0, isNum(j) ? j > i ? j : i + 1 : a.length) : [ a ];
}
function bless(ns, ctx) {
switch (n8iv_type(ns)) {
case "array":
break;
case "string":
ns = ns.split(".");
break;
default:
return blessCTX(ctx);
}
if (re_n8iv.test(ns[0])) {
ctx = n8iv;
ns.shift();
}
if (!ns.length) return blessCTX(ctx);
!ns[0].startsWith("^") || (ctx ? ns.shift() : ns[0] = ns[0].substring(1));
ctx = blessCTX(ctx);
ns.forEach(function(o) {
if (!o) return;
got(ctx, o) || (ctx[o] = n8iv_obj());
ctx = ctx[o];
m8.x.cache("Object", function(Type) {
function arraysEqual(a1, a2) {
return a1.length == a2.length && Array.coerce(a1).every(function(v, i) {
return Type.equalTo(a2[i], v);
});
return ctx;
}
function blessCTX(ctx) {
if (ENV == CJS) return ctx ? ctx instanceof Module ? ctx.exports : ctx : module.exports; else return ctx || root;
function objectsEqual(o1, o2) {
if (m8.len(o1) !== m8.len(o2) || Type.ownLen(o1) !== Type.ownLen(o2)) return false;
for (var k in o2) if (m8.has(o1, k) !== m8.has(o2, k) || !Type.equalTo(o1[k], o2[k])) return false;
return true;
}
function bool(o) {
switch (n8iv_type(o)) {
case F:
return F;
case "boolean":
m8.defs(Type, {
aggregate : function(o, val, fn, ctx) {
ctx || (ctx = o);
return Type.keys(o).reduce(function(res, k, i) {
return fn.call(ctx, res, o[k], k, o, i);
}, val);
},
clear : function(o) {
Type.keys(o).forEach(function(k) {
delete o[k];
}, o);
return o;
case "number":
return o !== 0 && !isNaN(o);
case "string":
return !booleans.some(function(v) {
return v === o;
},
equalTo : function(o, k) {
switch (m8.nativeType(o)) {
case "array":
return Array.isArray(k) ? arraysEqual(o, k) : false;
case "object":
return m8.nativeType(k) == "object" ? objectsEqual(o, k) : false;
case "date":
return +o == +k;
}
return o == k;
},
ownKeys : function(o) {
return Type.getOwnPropertyNames(o);
},
ownLen : function(o) {
return Type.ownKeys(o).length;
}
}, "w");
});
m8.x.cache("Function", function(Type) {
var re_args = /^[\s\(]*function[^\(]*\(([^\)]*)\)/, re_split = /\s*,\s*/;
m8.def(Type, "coerce", m8.describe(function coerce(o) {
return m8.nativeType(o) == "function" ? o : function() {
return o;
};
}, "w"));
m8.defs(Type.prototype, {
params : {
get : function() {
var names = String(this).match(re_args)[1].trim().split(re_split);
return names.length == 1 && !names[0] ? [] : names;
}
},
attempt : function(ctx) {
var args = Array.coerce(arguments, 1), fn = this;
return function attempting() {
try {
return fn.apply(ctx || this, args);
} catch (e) {
return e;
}
}();
},
bake : function() {
var baked = "baked", fn = this;
return fn[baked] || !m8.def(fn, baked, m8.describe(function() {
return fn.apply(this, [ this ].concat(Array.coerce(arguments)));
}.mimic(fn), "w")) || fn[baked];
},
defer : m8.ENV == "commonjs" ? function(ctx) {
return process.nextTick(this.bind.apply(this, [ ctx ].concat(Array.coerce(arguments, 1))));
} : function() {
return this.delay.apply(this, [ 1 ].concat(Array.coerce(arguments)));
},
delay : function(ms, ctx) {
var args = Array.coerce(arguments, 2), fn = this;
function delayed() {
delayed.stop();
return fn.apply(ctx || this, args);
}
return m8.copy(delayed, {
stop : function() {
clearTimeout(this.timeoutId);
delete this.timeoutId;
return fn;
},
timeoutId : setTimeout(delayed, ms)
});
default:
return o === U || o === N ? F : T;
},
memoize : function(cache) {
var fn = this;
m8.nativeType(cache) == "object" || (cache = m8.obj());
function memo() {
var args = Array.coerce(arguments), s = args.toString();
return s in cache ? cache[s] : cache[s] = fn.apply(this, args);
}
memo.unmemoize = function() {
return fn;
};
return memo;
},
stop : function() {
return this;
},
unmemoize : function() {
return this;
},
wrap : function(wrapper) {
var args = Array.coerce(arguments, 1), fn = this;
return function() {
return wrapper.apply(this, [ fn.bind(this) ].concat(args).concat(Array.coerce(arguments)));
}.mimic(wrapper);
}
}, "w");
});
m8.x.cache("Array", function(Type) {
function groupByFn(field, v) {
return field(v) ? 0 : 1;
}
function coerce(o, n, s) {
return !isNaN(n = Number(o)) ? n : (s = String(o)) in coercions ? coercions[s] : o;
function groupByRegExp(field, v) {
return field.test(v) ? 0 : 1;
}
function copy(d, s, n) {
n = n === T;
for (var k in s) !has(s, k) || n && has(d, k) || (d[k] = s[k]);
return d;
function groupByStr(field, v) {
return Object.value(v, field) || 1;
}
function def(item, name, desc, overwrite, debug) {
var exists = got(item, name);
!(desc.get || desc.set) || delete desc.writable;
if (overwrite === T || !exists) Object.defineProperty(item, name, desc); else if (debug === T && exists) trace().error(new Error("Trying to overwrite existing property: " + name + ", in: " + (isFn(item) ? item.n8ivName : item.constructor.n8ivName) + "."), T);
return n8iv;
function isFalsey(o) {
return !o ? null : o;
}
function defs(item, o, m, overwrite, debug) {
m || (m = "cw");
for (var k in o) !has(o, k) || def(item, k, describe(o[k], m), overwrite, debug);
return n8iv;
function sortedVal(o) {
return o[0];
}
function describe(v, m) {
return copy(isObj(v, T) ? v : {
value : v
}, isObj(m) ? m : modes[lc(m)] || modes.cew);
function sortingVal(o) {
return [ o, typeof this == "function" ? this(o) : Object.value(o, this) ];
}
function description(o, k) {
return Object.getOwnPropertyDescriptor(o, k);
}
function error(e, chuck) {
var msg;
switch (n8iv_type(e)) {
case "error":
msg = e.message;
break;
case "string":
msg = String(e);
e = new Error(e);
break;
var PROTO = Type.prototype, sort = {
desc : function(a, b) {
return a[1] == b[1] ? 0 : a[1] < b[1] ? 1 : -1;
},
asc : function(a, b) {
return a[1] == b[1] ? 0 : a[1] > b[1] ? 1 : -1;
}
!("error" in console) || console.error(msg);
if (chuck === T) throw e;
return n8iv;
}
function exists(o) {
return o !== N && o !== U && (typeof o == "number" ? !isNaN(o) : T);
}
function got(o, k) {
return k in Object(o);
}
function has(o, k) {
return OP.hasOwnProperty.call(o, k);
}
function lc(s) {
return String(s).toLowerCase();
}
function n8iv_id(o, prefix) {
return o ? got(o, "id") ? o.id : o.id = _id(prefix) : _id(prefix);
}
function _id(prefix) {
return (prefix || id_prefix) + ++id_count;
}
function n8iv_obj(o, n) {
return (n = Object.create(N)) && arguments.length >= 1 ? copy(n, o) : n;
}
function n8iv_proto(o) {
return Object.getPrototypeOf(o);
}
function noop() {}
function range(i, j) {
var a = [ i ];
while (++i <= j) a.push(i);
return a;
}
function requite(o) {
return o;
}
function tostr(o) {
return OP.toString.call(o);
}
function trace() {
!("trace" in console) || console.trace();
return n8iv;
}
function valof(o) {
return OP.valueOf.call(o);
}
function __type__() {
var ctor = this.constructor, nt = nativeType(this), t = ENV != CJS ? domType(nt) : re_global.test(nt) ? "global" : F;
return t || (nt == "object" && ctor.__type__ != "function" ? ctor.__type__ || lc(ctor.n8ivName) || nt : nt);
}
function domType(t) {
return re_col.test(t) ? "htmlcollection" : re_el.test(t) ? "htmlelement" : re_global.test(t) ? "global" : F;
}
function n8iv_type(o) {
return o === N || o === U ? F : o.__type__ || (n8iv_proto(o) === N ? "nullobject" : U);
}
function nativeType(o, t) {
if ((t = tostr(o)) in types) return types[t];
return types[t] = lc(t).match(re_type)[1].replace(re_vendor, "$1");
}
function isBool(o) {
return n8iv_type(o) == "boolean";
}
function isEmpty(o) {
switch (n8iv_type(o)) {
case "array":
return !o.length;
case "number":
return isNaN(o);
case "object":
return !Object.len(o);
case "string":
return o === "";
default:
return !exists(o);
}
}
function isFn(fn) {
return typeof fn == "function";
}
function isNum(o) {
return n8iv_type(o) == "number" && !isNaN(o);
}
function isObj(o, exclusive) {
var t = n8iv_type(o);
return t == "object" && nativeType(o) == "object" || exclusive !== T && t == "nullobject";
}
function isStr(o) {
return n8iv_type(o) == "string";
}
function isUndef(o) {
return typeof o == "undefined";
}
var F = !1, N = null, T = !0, U, CJS = "commonjs", ENV = typeof module != "undefined" && "exports" in module ? CJS : typeof navigator != "undefined" ? "browser" : "other", OP = Object.prototype, Module = ENV != CJS ? N : require("module"), booleans = [ 0, F, "", NaN, N, U ].map(String), coercions = [ F, NaN, N, T, U ].reduce(function(o, v) {
o[String(v)] = v;
return o;
}, n8iv_obj()), id_count = 999, id_prefix = "anon__", modes = function() {
var f = "configurable enumerable writable".split(" "), m = {
ce : "ec",
cw : "wc",
ew : "we",
cew : "cwe ecw ewc wce wec".split(" ")
}, p = {
c : [ T, F, F ],
ce : [ T, T, F ],
cew : [ T, T, T ],
cw : [ T, F, T ],
e : [ F, T, F ],
ew : [ F, T, T ],
r : [ F, F, F ],
w : [ F, F, T ]
}, v = Object.keys(p).reduce(function(o, k) {
o[k] = f.reduce(function(v, f, i) {
v[f] = p[k][i];
return v;
}, n8iv_obj());
!(k in m) || typeof m[k] == "string" ? o[m[k]] = o[k] : m[k].forEach(function(f) {
o[f] = o[k];
});
return o;
}, n8iv_obj());
delete v.undefined;
return v;
}(), n8iv = n8iv_obj(), re_col = /htmlcollection|nodelist/, re_el = /^html\w+?element$/, re_global = /global|window/i, re_n8iv = /^\u005E?n8iv/, re_type = /\[[^\s]+\s([^\]]+)\]/, re_vendor = /^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/, slice = Array.prototype.slice, types = {
"[object Object]" : "object"
};
def(OP, "__type__", copy({
get : __type__
}, modes.r));
def(Array, "from", describe($A, "w"));
defs(Object, {
clone : function(o) {
return copy(n8iv_obj(), o);
sort[String(true)] = sort[1] = sort.asc;
sort[String(!1)] = sort[0] = sort.desc;
m8.def(Type, "sortFns", m8.describe({
value : sort
}, "w"));
m8.defs(Type.prototype, {
aggregate : function(val, fn, ctx) {
return PROTO.reduce.call(this, function(val, o, i, a) {
return fn.call(ctx || o, val, o, i, a);
}, val);
},
each : function(o, fn, ctx) {
ctx || (ctx = o);
Object.keys(o).forEach(function(k, i) {
fn.call(ctx, o[k], k, o, i);
}, o);
return o;
associate : function(a, fn, ctx) {
fn || (fn = m8);
ctx || (ctx = this);
return PROTO.reduce.call(this, function(o, v, i) {
o[a[i]] = fn.call(ctx, v, i, this);
return o;
}, m8.obj());
},
key : function(o, v) {
for (var k in o) if (o[k] === v) return k;
return N;
clear : function() {
this.length = 0;
return this;
},
len : function(o) {
return Object.keys(o).length;
clone : function() {
return PROTO.slice.call(this);
},
remove : function(o, keys) {
(Array.isArray(keys) ? keys : $A(arguments, 1)).forEach(function(k) {
delete o[k];
compact : function(falsey) {
return PROTO.mapc.call(this, falsey === true ? isFalsey : m8);
},
contains : function(o) {
return !!~PROTO.indexOf.call(this, o);
},
each : function(fn, ctx) {
PROTO.forEach.call(this, fn, ctx || this);
return this;
},
flatten : function(n) {
if (m8.type(n) == "number") {
if (n > 0) --n; else return this;
}
return PROTO.aggregate.call(this, [], function(v, o, i) {
Type.isArray(o) ? v.splice.apply(v, [ v.length, 0 ].concat(o.flatten(n))) : v.push(o);
return v;
}, this);
},
grep : function(re, fn, ctx) {
var a = this;
fn || (fn = m8);
ctx || (ctx = a);
m8.nativeType(re) != "string" || (re = new RegExp(re.escapeRE(), "g"));
return PROTO.aggregate.call(a, [], function(v, o, i) {
!re.test(o) || v.push(fn.call(ctx, o, i, a));
return v;
});
return o;
},
value : function(o, k) {
if (isNaN(k) && !!~k.indexOf(".")) {
var v;
k = k.split(".");
while (v = k.shift()) {
o = Object.value(o, v);
if (o === U) return o;
}
return o;
groupBy : function(f, fn, ctx) {
fn || (fn = m8);
var a = this, keys, match, res = m8.obj();
switch (m8.type(f)) {
case "function":
match = groupByFn;
break;
case "regexp":
match = groupByRegExp;
break;
case "number":
case "string":
match = groupByStr;
keys = PROTO.pluck.call(a, f, true);
break;
default:
throw new TypeError("Array.prototype.groupBy can only match based on a Function, RegExp or String.");
}
return isEmpty(o) ? U : !isEmpty(o[k]) ? o[k] : isFn(o.get) ? o.get(k) : isFn(o.getAttribute) ? o.getAttribute(k) : U;
(keys || [ 0, 1 ]).forEach(function(k) {
res[k] = [];
});
return PROTO.aggregate.call(a, res, function(v, o, i) {
v[match(f, o)].push(fn.call(this, o, i, a));
return v;
}, ctx || a);
},
values : function(o) {
return Object.keys(o).map(function(k) {
return o[k];
include : function(o) {
return PROTO.contains.call(this, o) ? !1 : !this.push(o) || true;
},
invoke : function(fn) {
var args = Type.coerce(arguments, 1);
return PROTO.map.call(this, function(o, i) {
return o[fn].apply(o, args);
});
}
}, "w");
def(Array.prototype, "find", describe(function(fn, ctx) {
var i = -1, l = this.length >>> 0;
ctx || (ctx = this);
while (++i < l) if (!!fn.call(ctx, this[i], i, this)) return this[i];
return N;
}, "w"));
defs(Function.prototype, {
n8ivName : {
get : function() {
var anon = "anonymous", non = [ "", "" ], namu = "__n8ivName__", re_name = /[\s\(]*function([^\(]+).*/;
return function n8ivName() {
if (!this[namu]) {
var fn = this.valueOf(), m = fn !== this ? fn.n8ivName !== anon ? fn.n8ivName : N : N, n = this.name || this.displayName || (String(this).match(re_name) || non)[1].trim();
def(this, namu, describe(m || n || anon, "w"));
}
return this[namu];
};
}()
},
bind : function(ctx) {
var args = $A(arguments, 1), bound = function() {
return fn.apply(this instanceof bound ? this : ctx || root, args.concat($A(arguments)));
}, fn = this;
bound.prototype = Object.create(fn.prototype);
return bound.mimic(fn);
invokec : function(fn) {
var args = Type.coerce(arguments, 1);
return PROTO.mapc.call(this, function(o, i) {
return m8.nativeType(o[fn]) == "function" ? o[fn].apply(o, args) : null;
});
},
mimic : function(fn, name) {
return Object.defineProperties(this, {
displayName : describe(name || fn.n8ivName, "c"),
toString : describe(function() {
return fn.valueOf().toString();
}, "c"),
valueOf : describe(function() {
return fn;
}, "c")
item : function(i) {
return this[i < 0 ? this.length + i : i];
},
last : function() {
return this[this.length - 1];
},
mapc : function(fn, ctx) {
ctx || (ctx = this);
return PROTO.reduce.call(this, function(v, o, i, a) {
!m8.exists(o = fn.call(ctx, o, i, a)) || v.push(o);
return v;
}, []);
},
pluck : function(k, c) {
return PROTO[c === true ? "mapc" : "map"].call(this, function(o) {
return Object.value(o, k);
});
}
}, "w");
defs(String.prototype, {
endsWith : function(s) {
return this.length && this.lastIndexOf(s) == this.length - s.length;
},
lc : function() {
return lc(this);
remove : function() {
var args = Type.coerce(arguments), i, res = [], v;
while (v = args.shift()) !~(i = PROTO.indexOf.call(this, v)) || res.push(PROTO.splice.call(this, i, 1)[0]);
return res;
},
startsWith : function(s) {
return !this.indexOf(s);
sortBy : function(f, d) {
return PROTO.map.call(this, sortingVal, f).sort(m8.nativeType(d) == "function" ? d : sort[String(d).toLowerCase()] || sort.asc).map(sortedVal);
},
tuck : function(k, a) {
var is_arr = Type.isArray(a);
return PROTO.each.call(this, function(o, i) {
o[k] = is_arr ? a[i] : a;
});
},
uniq : function() {
return PROTO.reduce.call(this, function(v, o) {
v.contains(o) || v.push(o);
return v;
}, []);
},
without : function() {
var a = PROTO.clone.call(this);
a.remove.apply(a, arguments);
return a;
},
zip : function() {
var args = Type.coerce(arguments);
args.unshift(this);
return PROTO.map.call(this, function(o, i) {
return args.pluck(i);
});
}
}, "w");
typeof global == "undefined" || (root = global);
ENV != CJS ? def(root, "n8iv", describe({
value : n8iv
}, "w")) : module.exports = n8iv;
defs(n8iv, {
ENV : ENV,
modes : modes,
global : {
value : root
});
m8.x.cache("Number", function(Type) {
var abs = Math.abs, big_int = 9007199254740992, floor = Math.floor;
m8.defs(Type, {
isInteger : function(v) {
return m8.type(v) == "number" && isFinite(v) && v > -big_int && v < big_int && floor(v) === v;
},
bless : bless,
bool : bool,
coerce : coerce,
copy : copy,
def : def,
defs : defs,
describe : describe,
description : description,
error : error,
exists : exists,
got : got,
has : has,
id : n8iv_id,
isBool : isBool,
isEmpty : isEmpty,
isFn : isFn,
isNum : isNum,
isObj : isObj,
isStr : isStr,
isUndef : isUndef,
nativeType : nativeType,
noop : noop,
obj : n8iv_obj,
proto : n8iv_proto,
range : range,
requite : requite,
tostr : tostr,
trace : trace,
type : n8iv_type,
valof : valof
}, "w");
return n8iv;
}(this);
!function(n8iv) {
"use strict";
var F = !1, N = null, T = !0, U;
function aggregate(o, val, fn, ctx) {
ctx || (ctx = o);
return Object.keys(o).reduce(function(res, k, i) {
return fn.call(ctx, res, o[k], k, o, i);
}, val);
}
function clear(o) {
Object.keys(o).forEach(function(k) {
delete o[k];
}, o);
return o;
}
function equalTo(o, k) {
switch (n8iv.type(o)) {
case "array":
return Array.isArray(k) ? arraysEqual(o, k) : F;
case "object":
return n8iv.isObj(k) ? objectsEqual(o, k) : F;
case "date":
return +o == +k;
toInteger : function(v) {
v = +v;
if (isNaN(v)) return +0;
if (v === 0 || !isFinite(v)) return v;
return (v < 0 ? -1 : 1) * abs(floor(v));
}
return o == k;
}
function arraysEqual(a1, a2) {
return a1.length == a2.length && Array.from(a1).every(function(v, i) {
return equalTo(a2[i], v);
});
}
function objectsEqual(o1, o2) {
if (Object.len(o1) !== Object.len(o2) || ownLen(o1) !== ownLen(o2)) return F;
for (var k in o2) if (n8iv.has(o1, k) !== n8iv.has(o2, k) || !equalTo(o1[k], o2[k])) return F;
return T;
}
function ownKeys(o) {
return Object.getOwnPropertyNames(o);
}
function ownLen(o) {
return ownKeys(o).length;
}
function reduce(o, fn, val) {
return Object.keys(o).reduce(function(res, k, i) {
return fn.call(o, res, o[k], k, o, i);
}, val);
}
n8iv.defs(Object, {
aggregate : aggregate,
clear : clear,
equalTo : equalTo,
ownKeys : ownKeys,
ownLen : ownLen,
reduce : reduce
}, "w");
n8iv.defs(Function.prototype, function() {
var re_args = /^[\s\(]*function[^\(]*\(([^\)]*)\)/, re_split = /\s*,\s*/;
n8iv.def(Function, "from", n8iv.describe(function from(o) {
return n8iv.isFn(o) ? o : function() {
return o;
};
}, "w"));
return {
params : {
get : function() {
var names = String(this).match(re_args)[1].trim().split(re_split);
return names.length == 1 && !names[0] ? [] : names;
}
},
attempt : function(ctx) {
var args = Array.from(arguments, 1), fn = this;
return function attempting() {
try {
return fn.apply(ctx || this, args);
} catch (e) {
return e;
}
}();
},
bake : function() {
var baked = "baked", fn = this;
return fn[baked] || !n8iv.def(fn, baked, n8iv.describe(function() {
return fn.apply(this, [ this ].concat(Array.from(arguments)));
}.mimic(fn), "w")) || fn[baked];
},
defer : n8iv.ENV == "commonjs" ? function(ctx) {
return process.nextTick(this.bind.apply(this, [ ctx ].concat(Array.from(arguments, 1))));
} : function() {
return this.delay.apply(this, [ 1 ].concat(Array.from(arguments)));
},
delay : function(ms, ctx) {
var args = Array.from(arguments, 2), fn = this;
function delayed() {
delayed.stop();
return fn.apply(ctx || this, args);
}
return n8iv.copy(delayed, {
stop : function() {
clearTimeout(this.timeoutId);
delete this.timeoutId;
return fn;
},
timeoutId : setTimeout(delayed, ms)
});
},
memoize : function(cache) {
var fn = this;
n8iv.isObj(cache) || (cache = n8iv.obj());
function memo() {
var args = Array.from(arguments), s = args.toString();
return s in cache ? cache[s] : cache[s] = fn.apply(this, args);
}
memo.unmemoize = function() {
return fn;
};
return memo;
},
stop : function() {
return this;
},
unmemoize : function() {
return this;
},
wrap : function(wrapper) {
var args = Array.from(arguments, 1), fn = this;
return function() {
return wrapper.apply(this, [ fn.bind(this) ].concat(args).concat(Array.from(arguments)));
}.mimic(wrapper);
}
};
}(), "w");
n8iv.defs(Array.prototype, function() {
function groupByFn(field, v) {
return field(v) ? 0 : 1;
}
function groupByRegExp(field, v) {
return field.test(v) ? 0 : 1;
}
function groupByStr(field, v) {
return Object.value(v, field) || 1;
}
function isFalsey(o) {
return !o ? N : o;
}
function sortedVal(o) {
return o[0];
}
function sortingVal(o) {
return [ o, n8iv.isFn(this) ? this(o) : Object.value(o, this) ];
}
var AP = Array.prototype, sort = {
desc : function(a, b) {
return a[1] == b[1] ? 0 : a[1] < b[1] ? 1 : -1;
},
asc : function(a, b) {
return a[1] == b[1] ? 0 : a[1] > b[1] ? 1 : -1;
}
};
sort[String(T)] = sort[1] = sort.asc;
sort[String(!1)] = sort[0] = sort.desc;
n8iv.def(Array, "sortFns", n8iv.describe({
value : sort
}, "w"));
return {
aggregate : function(val, fn, ctx) {
return AP.reduce.call(this, function(val, o, i, a) {
return fn.call(ctx || o, val, o, i, a);
}, val);
},
associate : function(a, fn, ctx) {
fn || (fn = n8iv.requite);
ctx || (ctx = this);
return AP.reduce.call(this, function(o, v, i) {
o[a[i]] = fn.call(ctx, v, i, this);
return o;
}, n8iv.obj());
},
clear : function() {
this.length = 0;
return this;
},
clone : function() {
return AP.slice.call(this);
},
compact : function(falsey) {
return AP.mapc.call(this, falsey === T ? isFalsey : n8iv.requite);
},
contains : function(o) {
return !!~AP.indexOf.call(this, o);
},
each : function(fn, ctx) {
AP.forEach.call(this, fn, ctx || this);
return this;
},
flatten : function(n) {
if (n8iv.isNum(n)) {
if (n > 0) --n; else return this;
}
return AP.aggregate.call(this, [], function(v, o, i) {
Array.isArray(o) ? v.splice.apply(v, [ v.length, 0 ].concat(o.flatten(n))) : v.push(o);
return v;
}, this);
},
grep : function(re, fn, ctx) {
var a = this;
fn || (fn = n8iv.requite);
ctx || (ctx = a);
!n8iv.isStr(re) || (re = new RegExp(re.escapeRE(), "g"));
return AP.aggregate.call(a, [], function(v, o, i) {
!re.test(o) || v.push(fn.call(ctx, o, i, a));
return v;
});
},
groupBy : function(f, fn, ctx) {
fn || (fn = n8iv.requite);
var a = this, keys, match, res = n8iv.obj();
switch (n8iv.type(f)) {
case "function":
match = groupByFn;
break;
case "regexp":
match = groupByRegExp;
break;
case "number":
case "string":
match = groupByStr;
keys = AP.pluck.call(a, f, T);
break;
default:
n8iv.trace().error(new TypeError("Array.prototype.groupBy can only match based on a Function, RegExp or String."), T);
}
(keys || [ 0, 1 ]).forEach(function(k) {
res[k] = [];
});
return AP.aggregate.call(a, res, function(v, o, i) {
v[match(f, o)].push(fn.call(this, o, i, a));
return v;
}, ctx || a);
},
include : function(o) {
return AP.contains.call(this, o) ? !1 : !this.push(o) || T;
},
invoke : function(fn) {
var args = Array.from(arguments, 1);
return AP.map.call(this, function(o, i) {
return o[fn].apply(o, args);
});
},
invokec : function(fn) {
var args = Array.from(arguments, 1);
return AP.mapc.call(this, function(o, i) {
return n8iv.isFn(o[fn]) ? o[fn].apply(o, args) : N;
});
},
item : function(i) {
return this[i < 0 ? this.length + i : i];
},
last : function() {
return this[this.length - 1];
},
mapc : function(fn, ctx) {
ctx || (ctx = this);
return AP.reduce.call(this, function(v, o, i, a) {
!n8iv.exists(o = fn.call(ctx, o, i, a)) || v.push(o);
return v;
}, []);
},
pluck : function(k, c) {
return AP[c === T ? "mapc" : "map"].call(this, function(o) {
return Object.value(o, k);
});
},
remove : function() {
var args = Array.from(arguments), i, res = [], v;
while (v = args.shift()) !~(i = AP.indexOf.call(this, v)) || res.push(AP.splice.call(this, i, 1)[0]);
return res;
},
sortBy : function(f, d) {
return AP.map.call(this, sortingVal, f).sort(n8iv.isFn(d) ? d : sort[String(d).lc()] || sort.asc).map(sortedVal);
},
tuck : function(k, a) {
var is_arr = Array.isArray(a);
return AP.each.call(this, function(o, i) {
o[k] = is_arr ? a[i] : a;
});
},
uniq : function() {
return AP.reduce.call(this, function(v, o) {
v.contains(o) || v.push(o);
return v;
}, []);
},
without : function() {
var a = AP.clone.call(this);
a.remove.apply(a, arguments);
return a;
},
zip : function() {
var args = Array.from(arguments);
args.unshift(this);
return AP.map.call(this, function(o, i) {
return args.pluck(i);
});
}
};
}(), "w");
n8iv.defs(Number, function() {
var abs = Math.abs, big_int = 9007199254740992, floor = Math.floor;
return {
isInteger : function(v) {
return n8iv.isNum(v) && isFinite(v) && v > -big_int && v < big_int && floor(v) === v;
},
toInteger : function(v) {
v = +v;
if (isNaN(v)) return +0;
if (v === 0 || !isFinite(v)) return v;
return (v < 0 ? -1 : 1) * abs(floor(v));
}
};
}(), "cw");
n8iv.defs(Number.prototype, {
m8.defs(Type.prototype, {
pad : function(l, radix) {

@@ -680,3 +316,3 @@ var s = this.toString(radix || 10);

times : function(fn, ctx) {
n8iv.range(0, this).forEach(fn, ctx || n8iv.global);
m8.range(0, this).forEach(fn, ctx || m8.global);
return this;

@@ -688,650 +324,144 @@ },

}, "w");
n8iv.defs(String.prototype, function() {
var cache_chars = n8iv.obj(), cache_slices = n8iv.obj(), esc_chars = /([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g, esc_val = "\\$1", re_caps = /([A-Z])/g, re_gsub = /\$?\{([^\}]+)\}/g, re_hex = /#?(\w{1,6})/, re_rgb = /(\d{1,3})/g, re_split_string = /[\sA-Z_-]+/g;
function _splitString(m, p) {
return p + p.lc();
}
function splitString(s) {
s = s.trim();
var s0 = s.charAt(0), s1 = s.charAt(1), i = s0.lc() == s0 && s1 != " " && s1.uc() == s1 ? 2 : 1, o = s.substring(i).replace(re_caps, _splitString).split(re_split_string);
o[0] = s.substring(0, i) + o[0];
return o;
}
return {
blank : function() {
return !!this.trim().empty();
},
capitalize : function() {
return this.charAt(0).uc() + this.substring(1).lc();
},
cc : function() {
return this.toCamelCase();
},
clean : function(character) {
character || (character = " ");
character = cache_chars[character] || (cache_chars[character] = {
re : new RegExp("(" + character + "){1,}", "g"),
fill : character
});
return this.split(character.re).filter(function(s) {
return !s.blank() && s != character.fill;
}).join(character.fill);
},
contains : function(s) {
return !!~this.indexOf(s);
},
empty : function() {
return String(this) === "";
},
format : function() {
return this.gsub.call(this, Array.from(arguments));
},
gsub : function(o, pattern) {
return this.replace(pattern || re_gsub, function(m, p) {
return o[p] || "";
});
},
hyphenate : function() {
return splitString(this).join("-").lc();
},
includes : function(s) {
return this.lc().contains(String(s).lc());
},
parts : function(re) {
var m = Array.from(this.match(re));
switch (m.length) {
case 1:
if (m[0] === N || m[0] === this) return [];
default:
m[0] !== this || m.shift();
return m;
}
},
qw : function() {
return this.split(" ");
},
regexpEsc : function() {
return this.replace(esc_chars, esc_val);
},
sliceEvery : function(n) {
n = parseInt(n, 10);
if (isNaN(n) || this.length < n || n == 0) return [ String(this) ];
return this.match(cache_slices[n] || (cache_slices[n] = new RegExp("(.{1," + n + "})", "g")));
},
times : function(n) {
return (new Array(Number.toInteger(n) + 1)).join(this);
},
toCamelCase : function() {
var parts = splitString(this), str = [ parts.shift() ];
return parts.reduce(function(res, val) {
res.push(val.capitalize());
return res;
}, str).join("");
},
toHex : function() {
function toHex(o) {
return parseInt(o, 10).pad(2, 16);
}
return function() {
var m = this.match(re_rgb);
return "#" + (m.length == 1 ? toHex(m[0]).times(3) : m.map(toHex).join(""));
};
}(),
toJSON : function() {
return JSON.parse(this);
},
toRGB : function(as_array) {
var o = this.match(re_hex)[1], l = o.length, v;
switch (l) {
case 6:
break;
case 3:
o = this.times(2);
break;
case 2:
o = this.times(3);
break;
default:
o = l > 6 ? o.substring(0, 6) : l == 4 ? o + "00" : o + "0";
}
v = o.sliceEvery(2).map(function(v) {
return parseInt(v, 16);
});
return as_array === T ? v : "rgb(" + v.join(", ") + ")";
},
truncate : function(i, c) {
i || (i = 50);
n8iv.isStr(c) || (c = "...");
return this.length < i ? String(this) : this.substring(0, i).trimRight() + c;
},
uc : function() {
return this.toUpperCase();
},
underscore : function() {
return splitString(this).join("_").lc();
}
};
}(), "w");
n8iv.ENV != "commonjs" || module.exports === n8iv || (module.exports = n8iv);
}(typeof n8iv != "undefined" ? n8iv : typeof require != "undefined" ? require("./n8iv._") : null);
!function(n8iv) {
"use strict";
var F = !1, N = null, T = !0, U;
!function() {
function Class(path, desc) {
if (!desc && n8iv.isObj(path)) {
desc = path;
path = "";
}
var C, name, ns, _ctor, _proto = n8iv.obj(), _super = desc.extend || Object, mod = desc.module, mixin = desc.mixin || dumb, singleton = desc.singleton, type = getType(desc.type || path);
!n8iv.isStr(_super) || (_super = reg_path[_super] || reg_type[_super]);
_ctor = desc.constructor !== Object ? desc.constructor : _super;
if (path) {
ns = path.split(".");
name = ns.pop();
ns = n8iv.bless(ns, mod);
}
n8iv.def(_proto, "parent", n8iv.describe(n8iv.noop, "cw"), T);
n8iv.def(_proto, "constructor", n8iv.describe(ctor(_ctor, _super, name, _proto), "w"), T);
C = _proto.constructor;
n8iv.def(C, "__type__", n8iv.describe("class", "w"), T);
n8iv.def(_proto, "__type__", n8iv.describe(type, "w"), T);
Object.remove(desc, defaults);
C.prototype = apply(_proto, n8iv.copy(desc, mixin));
n8iv.def(C, "create", n8iv.describe(create(extend(C, _super)), "w"), T);
path = path.replace(re_root, "");
if (singleton) {
n8iv.def(C, "singleton", n8iv.describe({
value : singleton === T ? new C : C.create.apply(C, [].concat(singleton))
}, "w"));
register(C, path, type);
C = C.singleton;
} else if (path) register(C, path, type);
!(name && ns) || n8iv.def(ns, name, n8iv.describe({
value : C
}, "w"));
return C;
}
function apply(proto, desc) {
Object.each(desc, function(v, k) {
switch (n8iv.type(v)) {
case "object":
n8iv.def(proto, k, v, T);
break;
default:
proto[k] = v;
}
});
m8.x.cache("String", function(Type) {
var cache_chars = m8.obj(), cache_slices = m8.obj(), esc_chars = /([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g, esc_val = "\\$1", re_caps = /([A-Z])/g, re_gsub = /\$?\{([^\}]+)\}/g, re_hex = /#?(\w{1,6})/, re_rgb = /(\d{1,3})/g, re_split_string = /[\sA-Z_-]+/g;
function _splitString(m, p) {
return p + p.toLowerCase();
}
function splitString(s) {
s = s.trim();
var s0 = s.charAt(0), s1 = s.charAt(1), i = s0.toLowerCase() == s0 && s1 != " " && s1.toUpperCase() == s1 ? 2 : 1, o = s.substring(i).replace(re_caps, _splitString).split(re_split_string);
o[0] = s.substring(0, i) + o[0];
return o;
}
m8.defs(Type.prototype, {
blank : function() {
return !!this.trim().empty();
},
capitalize : function() {
return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
},
clean : function(character) {
character || (character = " ");
character = cache_chars[character] || (cache_chars[character] = {
re : new RegExp("(" + character + "){1,}", "g"),
fill : character
});
return proto;
}
function create(C) {
return function create() {
return singleton(C) || C.apply(Object.create(C.prototype), arguments);
};
}
function ctor(m, s, name, P) {
var C = wrap(m, s, name), Ctor = function() {
var ctx = this === U ? N : this, ctor = ctx ? ctx.constructor : N;
return singleton(ctor) || C.apply(is(ctx, Ctor) ? ctx : Object.create(P), arguments);
};
return Ctor.mimic(m, name);
}
function extend(C, Sup) {
if (!("__super" in C.prototype)) {
var p = C.prototype, sp = Sup.prototype;
Object.keys(sp).forEach(function(k) {
if (k in reserved) return;
switch (n8iv.type(sp[k])) {
case "function":
p[k] = !n8iv.isFn(p[k]) ? wrap(sp[k], n8iv.noop, k) : wrap(p[k], sp[k], k);
break;
default:
k in p || n8iv.def(p, k, n8iv.description(sp, k), T);
}
});
Object.keys(p).forEach(function(k) {
!(n8iv.isFn(p[k]) && (!(k in sp) || p[k].valueOf() !== sp[k].valueOf())) || (p[k] = wrap(p[k], n8iv.noop, k));
});
sp = n8iv.describe({
value : Object.create(Sup.prototype)
}, "w");
n8iv.def(C, "__super", sp);
n8iv.def(C.prototype, "__super", sp);
return this.split(character.re).filter(function(s) {
return !s.blank() && s != character.fill;
}).join(character.fill);
},
contains : function(s) {
return !!~this.indexOf(s);
},
empty : function() {
return Type(this) === "";
},
endsWith : function(s) {
return this.length && this.lastIndexOf(s) == this.length - s.length;
},
format : function() {
return this.gsub.call(this, Array.coerce(arguments));
},
gsub : function(o, pattern) {
return this.replace(pattern || re_gsub, function(m, p) {
return o[p] || "";
});
},
hyphenate : function() {
return splitString(this).join("-").toLowerCase();
},
includes : function(s) {
return this.toLowerCase().contains(Type(s).toLowerCase());
},
parts : function(re) {
var m = Array.coerce(this.match(re));
switch (m.length) {
case 1:
if (m[0] === null || m[0] === this) return [];
default:
m[0] !== this || m.shift();
return m;
}
return C;
}
function getType(type) {
return type.replace(re_root, "").replace(re_dot, "_").lc();
}
function is(o, C) {
if (o && C) {
if (o instanceof C) return T;
if (!(o = o.constructor)) return F;
do {
if (o === C) return T;
} while (o.__super && (o = o.__super.constructor));
},
regexpEsc : function() {
return this.replace(esc_chars, esc_val);
},
sliceEvery : function(n) {
n = parseInt(n, 10);
if (isNaN(n) || this.length < n || n == 0) return [ Type(this) ];
return this.match(cache_slices[n] || (cache_slices[n] = new RegExp("(.{1," + n + "})", "g")));
},
startsWith : function(s) {
return !this.indexOf(s);
},
times : function(n) {
return (new Array(Number.toInteger(n) + 1)).join(this);
},
toCamelCase : function() {
var parts = splitString(this), str = [ parts.shift() ];
return parts.reduce(function(res, val) {
res.push(val.capitalize());
return res;
}, str).join("");
},
toHex : function() {
function toHex(o) {
return parseInt(o, 10).pad(2, 16);
}
return F;
}
function register(C, path, type) {
var err_msg = path + ERR_MSG, msg = [];
!path || !(path in reg_path) || msg.push(err_msg + "Class");
!type || !(type in reg_type) || msg.push(err_msg + "Type");
if (msg.length) {
n8iv.trace();
msg.forEach(n8iv.error);
n8iv.error(new Error("n8iv.Class overwrite error."), T);
}
reg_path[path] = reg_type[type] = C;
}
function singleton(C) {
return !C ? N : C.singleton || N;
}
function type(c) {
var ctor = c.constructor, k;
for (k in reg_path) if (reg_path[k] === ctor) return k;
return N;
}
function wrap(m, s, name) {
return function() {
var o, p = n8iv.description(this, "parent") || desc_noop;
p.writable = T;
n8iv.def(this, "parent", s ? n8iv.describe(s, "cw") : desc_noop, T);
o = m.apply(this, arguments);
n8iv.def(this, "parent", p, T);
return this.chain !== F && o === U ? this : o;
}.mimic(m, name);
}
var ERR_MSG = " already exists. Cannot override existing ", defaults = "constructor extend mixin module singleton type".split(" "), desc_noop = n8iv.describe(n8iv.noop, "cw"), dumb = n8iv.obj(), re_dot = /\./g, re_root = /^\u005E/, reg_path = n8iv.obj(), reg_type = n8iv.obj(), reserved = n8iv.obj();
reserved.constructor = reserved.parent = reserved.__super = reserved.__type__ = T;
n8iv.def(Class, "is", n8iv.describe(is, "w")).def(Class, "type", n8iv.describe(type, "w")).def(n8iv, "Class", n8iv.describe(Class, "w")).def(n8iv, "create", n8iv.describe(function(n) {
var C = reg_type[n] || reg_type["n8iv_" + n] || reg_path[n], args = Array.from(arguments, 1);
C || n8iv.trace().error(new Error(n + " does not match any registered n8iv.Classes."), T);
return C.create.apply(n8iv.global, args);
}, "w"));
}();
n8iv.Class("n8iv.Callback", function() {
n8iv.def(Function.prototype, "callback", n8iv.describe(function(conf) {
return (new n8iv.Callback(this, conf)).fire.mimic(this);
}, "w"));
function buffer() {
if (bid in this) return this;
this[bid] = setTimeout(buffer_stop.bind(this), this.buffer);
return this.exec.apply(this, arguments);
}
function buffer_stop() {
clearTimeout(this[bid]);
delete this[bid];
}
function handleEvent() {
return this.fire.apply(this, arguments);
}
var bid = "bufferId", he = "handleEvent", tid = "timeoutId";
return {
constructor : function Callback(fn, conf) {
n8iv.copy(this, conf || n8iv.obj());
var desc = n8iv.describe(N, "w"), fire = (n8iv.isNum(this.buffer) ? buffer : this.exec).bind(this);
desc.value = fn;
n8iv.def(this, "fn", desc);
desc.value = this;
n8iv.def(fire, "cb", desc);
desc.value = fire;
n8iv.def(this, "fire", desc);
this.args || (this.args = []);
this.ctx || (this.ctx = this);
n8iv.isNum(this.delay) || (this.delay = N);
n8iv.isNum(this.times) && this.times > 0 || (this.times = 0);
this.enable();
},
chain : T,
buffer : N,
count : 0,
delay : N,
times : 0,
disable : function() {
this.disabled = T;
this[he] = n8iv.noop;
},
enable : function() {
this.disabled = F;
this[he] = handleEvent;
},
exec : function() {
if (this.disabled) return;
this.times === 0 || this.times > ++this.count || this.disable();
var a = Array.from(arguments), me = this, ctx = me.ctx, ms = me.delay, t = n8iv.type(a[0]), v;
t && (t.endsWith("event") || t == "n8iv_observer") ? a.splice.apply(a, [ 1, 0 ].concat(me.args)) : a.unshift.apply(a, me.args);
ms === N ? v = me.fn.apply(ctx, a) : this[tid] = setTimeout(function() {
me.fn.apply(ctx, a);
}, ms);
return v;
},
reset : function() {
this.count = 0;
buffer_stop.call(this.enable());
},
stop : function() {
!(tid in this) || clearTimeout(this[tid]), delete this[tid];
}
};
}());
n8iv.Class("n8iv.Hash", function() {
var ID = "__hashid__", cache = [];
return {
constructor : function Hash(o) {
n8iv.def(this, ID, n8iv.describe(cache.push(n8iv.obj()) - 1, "w"));
!n8iv.isObj(o) || this.set(o);
},
keys : {
get : function() {
return Object.keys(cache[this[ID]]);
}
},
length : {
get : function() {
return this.keys.length;
}
},
values : {
get : function() {
return Object.values(cache[this[ID]]);
}
},
aggregate : function(val, fn, ctx) {
var hash = this, o = cache[this[ID]];
ctx || (ctx = hash);
return Object.keys(o).reduce(function(res, k, i) {
return fn.call(ctx, res, o[k], k, hash, i);
}, val);
},
clear : function() {
cache[this[ID]] = n8iv.obj();
},
clone : function() {
return new n8iv.Hash(Object.clone(cache[this[ID]]));
},
each : function(fn, ctx) {
var hash = this, o = cache[this[ID]];
ctx || (ctx = hash);
Object.keys(o).forEach(function(k, i) {
fn.call(ctx, o[k], k, hash, i);
}, hash);
return hash;
},
get : function(k) {
return n8iv.has(cache[this[ID]], k) ? cache[this[ID]][k] : N;
},
has : function(k) {
return n8iv.has(cache[this[ID]], k);
},
key : function(v) {
return Object.key(cache[this[ID]], v);
},
reduce : function(fn, val) {
var hash = this, o = cache[this[ID]];
return Object.keys(o).reduce(function(res, k, i) {
return fn.call(hash, res, o[k], k, hash, i);
}, val);
},
remove : function(k) {
return n8iv.has(cache[this[ID]], k) ? delete cache[this[ID]][k] : F;
},
set : function(o, v) {
switch (n8iv.type(o)) {
case "object":
case "nullobject":
Object.keys(o).forEach(function(k) {
this.set(k, o[k]);
}, this);
break;
default:
cache[this[ID]][o] = v;
}
},
stringify : function() {
return JSON.stringify(cache[this[ID]]);
},
toString : function() {
return n8iv.tostr(cache[this[ID]]);
},
valueOf : function() {
return Object.clone(cache[this[ID]]);
}
};
}());
n8iv.Class("n8iv.Observer", function() {
function addObservers(observers) {
observers = Object.clone(observers);
var ctx = observers[_ctx], k, l, o, opt = observers[_options], s;
Object.remove(observers, _ctx, _options);
for (k in observers) {
l = observers[k];
o = !n8iv.isUndef(l[_options]) ? l[_options] : opt;
s = !n8iv.isUndef(l[_ctx]) ? l[_ctx] : ctx;
switch (n8iv.type(l)) {
case "function":
this.on(k, l, ctx, opt);
break;
case "object":
case "nullobject":
switch (n8iv.type(l[_fn])) {
case "function":
case "object":
case "nullobject":
this.on(k, l[_fn], s, o);
break;
case "array":
l[_fn].forEach(function(fn) {
this.on(k, fn, s, o);
}, this);
break;
}
break;
case "array":
l.forEach(function(fn) {
this.on(k, fn, ctx, opt);
}, this);
break;
}
}
return this;
}
function broadcast(cb) {
var args = this.args.concat(cb[_options].args), ctx = cb[_ctx] || this[_ctx], fire = cb.fire || cb[_fn];
if (!n8iv.isFn(fire)) return T;
if (!!Object.key(this[_ctx], cb[_fn])) args[0] !== this[_ctx] || args.shift(); else if (args[0] !== this[_ctx]) args.unshift(this[_ctx]);
return fire.apply(ctx, args) !== F;
}
function createRelayCallback(ctxr, ctx, evt) {
return function Observer_relayedCallback() {
var args = Array.from(arguments);
!(args[0] === ctxr) || args.shift();
args.unshift(evt, ctx);
return relay.apply(ctx, args);
var m = this.match(re_rgb);
return "#" + (m.length == 1 ? toHex(m[0]).times(3) : m.map(toHex).join(""));
};
}
function createSingleCallback(event, cb) {
var ctx = this;
return cb.fire = function Observer_singleCallback() {
ctx.un(event, cb[_fn], cb[_ctx]);
if (cb.fired) {
return;
}
cb.fired = T;
return cb[_fn].apply(cb[_ctx] || ctx, arguments);
};
}
function handleEvent(cb) {
return function handleEvent() {
return cb.handleEvent.apply(cb, arguments);
}.mimic(cb.fire);
}
function ignore(event, fn, ctx) {
event = event.lc();
var e = this[_observers].get(event), i, o;
if (!e) {
return;
}
switch (n8iv.type(fn)) {
case "n8iv_callback":
o = {
ctx : fn,
isCB : T
};
}(),
toJSON : function() {
return JSON.parse(this);
},
toRGB : function(as_array) {
var o = this.match(re_hex)[1], l = o.length, v;
switch (l) {
case 6:
break;
default:
o = {
ctx : ctx || this,
fn : fn
};
}
o.event = event;
o = e.find(matchCallback, o);
if (o !== N) {
i = e.indexOf(o);
i < 0 || e.splice(i, 1);
}
}
function matchCallback(o) {
return (this.isCB === T ? o[_fn].valueOf() === this[_ctx].fire : o[_fn] === this[_fn]) && o[_ctx] === this[_ctx] && o.event === this.event;
}
function observe(event, fn, ctx, o) {
var cb, e = this[_observers], fnt, q;
if (n8iv.isObj(event)) return addObservers.call(this, event);
switch (fnt = n8iv.nativeType(fn)) {
case "array":
cb = n8iv.obj();
cb[event] = {
fn : fn,
options : o,
ctx : ctx
};
return addObservers.call(this, cb);
case "object":
case "nullobject":
case "n8iv_callback":
if ("handleEvent" in fn) {
!(n8iv.isObj(ctx) && n8iv.isUndef(o)) || (o = ctx);
ctx = fn;
fn = handleEvent(fn);
}
case 3:
o = this.times(2);
break;
case "string":
!ctx || (fn = ctx[fn]);
case 2:
o = this.times(3);
break;
}
event = event.lc();
(q = e.get(event)) || e.set(event, q = []);
switch (n8iv.type(o)) {
case "boolean":
o = {
single : !!o
};
break;
case "number":
o = {
delay : o
};
break;
case "object":
case "nullobject":
o = Object.clone(o);
break;
default:
o = n8iv.obj();
o = l > 6 ? o.substring(0, 6) : l == 4 ? o + "00" : o + "0";
}
Array.isArray(o.args) || (o.args = []);
cb = {
ctx : ctx || this,
event : event,
fn : fn,
id : ++listener_id,
options : o
};
cb.fire = (o.single ? createSingleCallback.call(this, event, cb) : cb[_fn]).callback({
args : o.args,
buffer : o.buffer,
ctx : cb[_ctx],
delay : o.delay
v = o.sliceEvery(2).map(function(v) {
return parseInt(v, 16);
});
q.push(cb);
return as_array === true ? v : "rgb(" + v.join(", ") + ")";
},
truncate : function(i, c) {
i || (i = 50);
m8.nativeType(c) == "string" || (c = "...");
return this.length < i ? Type(this) : this.substring(0, i).trimRight() + c;
},
underscore : function() {
return splitString(this).join("_").toLowerCase();
}
function relay() {
return this.broadcast.apply(this, arguments);
}
var _broadcasting = "broadcasting", _ctx = "ctx", _destroyed = "destroyed", _fn = "fn", _observers = "listeners", _options = "options", _suspended = "observer_suspended", listener_id = 0;
return {
constructor : function Observer(observers) {
this[_broadcasting] = F;
this[_destroyed] = F;
this[_suspended] = F;
this[_observers] = n8iv.Hash.create();
!n8iv.isObj(observers) || this.on(observers);
!n8iv.isObj(this.observers) || this.on(this.observers), delete this.observers;
},
broadcast : function(event) {
if (this[_destroyed] || this[_suspended] || !this[_observers].length || !event || !this[_observers].has(event = event.lc())) return;
var args = Array.from(arguments, 1), e = this[_observers].get(event).slice();
if (!e.length) return;
this[_broadcasting] = event;
e.every(broadcast, {
args : args,
ctx : this
});
this[_broadcasting] = F;
},
buffer : function(ms, evt, fn, ctx, o) {
n8iv.isObj(o) || (o = n8iv.obj());
o.buffer = Number.toInteger(ms);
this.on(evt, fn, ctx, o);
},
delay : function(ms, evt, fn, ctx, o) {
n8iv.isObj(o) || (o = n8iv.obj());
o.delay = Number.toInteger(ms);
this.on(evt, fn, ctx, o);
},
destroy : function() {
if (this[_destroyed]) return T;
if (this.broadcast("before:destroy") === F) return F;
this[_destroyed] = T;
this._destroy();
this.broadcast("destroy");
this[_suspended] = T;
delete this[_observers];
return T;
},
ignore : ignore,
observe : observe,
on : observe,
once : function(evt, fn, ctx, o) {
n8iv.isObj(o) || (o = n8iv.obj());
o.single = T;
this.on(evt, fn, ctx, o);
},
purgeObservers : function(event) {
var e = this[_observers];
if (!event) {
e.clear();
return;
}
event = event.lc();
!e.has(event) || e.set(event, []);
},
relayEvents : function(o) {
var e = Array.from(arguments, 1), evt;
while (evt = e.shift()) this.on(evt, createRelayCallback(this, o, evt), o);
},
resumeEvents : function() {
!this[_suspended] || (this[_suspended] = F, this.broadcast("observer:resumed"));
},
suspendEvents : function() {
this[_suspended] || (this[_suspended] = T, this.broadcast("observer:suspended"));
},
un : ignore,
_destroy : n8iv.noop
};
}());
n8iv.ENV != "commonjs" || module.exports === n8iv || (module.exports = n8iv);
}(typeof n8iv != "undefined" ? n8iv : typeof require != "undefined" ? require("./n8iv._") : null);
n8iv.ENV != "commonjs" || module.exports === n8iv || (module.exports = n8iv);
}(this);
}, "w");
});
function n8iv() {
m8.x.apply(m8, arguments);
return n8iv;
}
function x(Type, extender) {
m8.x.cache(Type.__name__, extender).x(Type);
return n8iv;
}
m8.defs(n8iv, {
m8 : {
value : m8
},
x : x
}, "r");
m8.ENV != "commonjs" ? m8.def(m8.global, "n8iv", m8.describe({
value : n8iv
}, "r")) : module.exports = n8iv;
m8.x(Object, Array, Function, Number, String);
}(typeof m8 != "undefined" ? m8 : typeof require != "undefined" ? require("m8") : null);

@@ -7,8 +7,5 @@ {

},
"description" : "n8iv is an object-oriented & functional programming library – for modern javascript engines – which correctly extends JavaScript Natives, as well as providing other useful Classes. Giving you a – relatively – safe and easy to use API, to help make your code more succinct and efficient.",
"devDependencies" : {
"Templ8" : ">= 0.3.0",
"mkdirp" : ">= 0.3.0",
"uglify-js" : ">= 1.2.5"
},
"description" : "n8iv is a functional programming library – for modern javascript engines – which correctly extends JavaScript Natives. Giving you a – relatively – safe and easy to use API, to make your code more succinct and efficient.",
"dependencies" : { "m8" : ">= 0.1.0" },
"devDependencies" : { "Templ8" : ">= 0.3.0", "mkdirp" : ">= 0.3.0", "uglify-js" : ">= 1.2.5" },
"keywords" : ["api", "framework", "functional", "javascript", "library", "object-oriented", "programming"],

@@ -25,3 +22,3 @@ "licenses" : [ {

},
"version" : "0.1.1"
"version" : "0.2.0"
}

@@ -0,37 +1,55 @@

# MENTAL NOTE: THIS REPOSITORY HAS BEEN SPLIT INTO 3
I have decided that the former **n8iv** API would function better as 3 separate libraries:
1. [m8.js](/constantology/m8): what used to be n8iv._, will now serve as a base for most of my libraries, to eliminate duplicate utility methods
2. [id8.js](/constantology/id8): this is the old n8iv.Oo; and
3. n8iv.js: this is the old n8iv.Fn, which is this repository... right... here...
Apologies for any inconvenience caused.
# n8iv.js
n8iv is a functional programming library – for modern javascript engines – which correctly extends JavaScript Natives. Giving you a – relatively – safe and easy to use API, to make your code more succinct and efficient.
n8iv is an object-oriented & functional programming library – for modern javascript engines – which correctly extends JavaScript Natives – using Object.defineProperty. As well as providing other useful Classes. Giving you a – relatively – safe and easy to use API, to help make your code more succinct and efficient.
n8iv is based on the awesomeness of [prototypejs](https://github.com/savetheclocktower/prototype).
If you like the idea of having one global variable with a bunch of static functions – in no particular order – attached to it, then this is probably not the framework for you. If, however, you like your methods bound to your types, then come on in and sit a spell!
If you like the idea of having one global variable with a bunch of static functions – in no particular order – attached to it, then this is probably not the framework for you.
If you think that extending JavaScript Natives is a "bad part" of JavaScript, then this is probably not the framework for you.
If, however, you like your methods bound to your types, then come on in and sit a spell!
**n8iv will not overwrite any implementations – native or otherwise – of any methods, properties or accessors already defined.**
n8iv comes in 3 parts:
## WARNING!!!
While **n8iv** has been tested, the testing framework I've written and used is very much a work in progress.
- `n8iv._.js` : is where all the base n8iv functionality – used across the other 2 parts – is defined.
- `n8iv.Fn.js` : is where all the extensions to JavaScript's natives takes place.
- `n8iv.Oo.js` : is where the n8iv Class system and a few useful Classes are defined.
Also I'm currently between virtual machine software and operating system licenses, so I have only tested on mac osx lion and snow leopard: nodejs – >= v0.613 – as well as current – and beta/ nightly – versions of Chrome, Safari/ Webkit and FireFox.
All of the above are pakaged as a single file: `n8iv.js`.
## Dependencies
If you don't like the idea of extending JavaScript natives, you can still to take advantage of the functionality defined in: `n8iv._.js` and `n8iv.Oo.js`.
n8iv.js only has one dependency [m8.js](/constantology/m8).
## WARNING!!!
**NOTE:**
If you are using n8iv within a commonjs module, you don't need to require m8 before requiring n8iv as this is done internally and a reference to **m8** is available as: `n8iv.m8`.
This is an, as yet, untested framework, use at your own risk!
```javascript
## File sizes
var n8iv = require( 'n8iv' ),
m8 = n8iv.m8; // <= reference to m8
// if running in a sandboxed environment remember to:
m8.x( Object, Array, Boolean, Function, String ); // and/ or any other Types that require extending.
// alternatively, this does the same and returns the n8iv global
n8iv( Object, Array, Boolean, Function, String );
```
See [m8: Extending into the future](/constantology/m8) for more information on working with sandboxed modules.
## File size
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr><td style="width : 80px ;">n8iv._.js</td><td style="width : 48px ;">3.4kb</td><td>deflate</td>
<tr><td>n8iv._.min.js</td><td>2.6kb</td><td>uglified + deflate</td>
<tr><td>n8iv.Fn.js</td><td>4.0kb</td><td>deflate</td>
<tr><td>n8iv.Fn.min.js</td><td>3.1kb</td><td>uglified + deflate</td>
<tr><td>n8iv.Oo.js</td><td>4.4kb</td><td>deflate</td>
<tr><td>n8iv.Oo.min.js</td><td>3.3kb</td><td>uglified + deflate</td>
<tr><td>n8iv.js</td><td>10.9kb</td><td>deflate</td>
<tr><td>n8iv.min.js</td><td>8.1kb</td><td>uglified + deflate</td>
<tr><td style="width : 80px ;">n8iv.js</td><td style="width : 48px ;">4.1kb</td><td>deflate</td>
<tr><td>n8iv.min.js</td><td>3.1kb</td><td>uglified + deflate</td>
</tbody>

@@ -38,0 +56,0 @@ </table>

Sorry, the diff of this file is not supported yet