pn

part-native

generate helpful methods from native objects using _part_

Showing:

Popularity

Downloads/wk

0

GitHub Stars

1

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Build Status NPM version

part-native

generate helpful methods from native objects using _part_

Why?

  • With one small lib, you can use part to safely expose all available methods of an object. This can help make code more modular, functional, and maintainable.
  • When passing functions as first-class objects, we often lose the method receiver (thisArg). part-native methods are bound to their context or will allow you to curry the context.
  • Array methods will work on ArrayLike objects (including Arguments objects) so your code will contain less type checking and slicing of arguments.
  • By using part-native at startup, your application will have cached versions of the functions you need, immune to attempts to hack the native object prototypes.
  • Turn your own simple prototypes into part-style method collections.

Getting started

Installation:

npm install --save part-native

Or

download and include the script lib/part-native.min.js

Or

include the script from a CDN:

<script src="https://cdn.rawgit.com/AutoSponge/part-native/master/lib/part-native.min.js"></script>

Usage:

Get a reference to a bound function on a native object.

var log = require( 'part-native' )( 'console' ).log;
[1,2,3].map( log );

try it

or

var map_ = require( 'part-native' )( 'Array.map_' );
var logAll = map_( log );
logAll( [1,2,3] );

try it

Get a reference to a collection of methods.

var partArray = require( 'part-native' )( 'Array' );
var sum = partArray.reduce_( add );

or use your own objects

function Klass( id ){
  this.id = id;
}
Klass.prototype.test = function ( msg ) {
  console.log( msg + this.id );
};
var partKlass = require( 'part-native' )( 'Klass', Klass );
var klassMsg = partKlass.test_( 'hi from ' );
klassMsg( new Klass( 1 ) );

try it

If you're using part-native in the browser, use the global method createPart:

var map_ = createPart( 'Array.map_' );
var add1 = function (n) {return n + 1;}
var incAll = map_( add1 );
incAll( [1,2,3] ) // -> [2,3,4]

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial