GithubHelp home page GithubHelp logo

gsklee / bound-native-methods Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 3.0 29 KB

Bound native virtual methods to be used together with ES7 :: bind operator.

License: MIT License

JavaScript 93.02% Shell 6.98%

bound-native-methods's Introduction

Bound Native Methods

This library exports a collection of bound native virtual methods - static methods of JavaScript standard built-in objects in their bound form - so that they can be used together with the proposed bind operator.

Install

$ npm install bound-native-methods

Usage

import * from 'bound-native-methods';

// Or, be more specific and cut down the build size: //

import {assign, keys} from 'bound-native-methods/object';
0::isInteger();
// true
[3, 6, 9]::max()::is(9);
// true
{'2015-06-01T15:30:00.000Z': 300}::assign({'2015-07-01T15:30:00.000Z': 42})
                                 ::keys()
                                  .map(x => x::toUnixOffset())
                                 ::toJSON();
// [1433172600000,1435764600000]

API

Most static methods have been exported as is, but a few have been renamed or excluded to better fit the context:

Object

Bound Form Native Form
::assign() Object.assign()
::create() Object.create()
::defineProperties() Object.defineProperties()
::defineProperty() Object.defineProperty()
::freeze() Object.freeze()
::getOwnPropertyDescriptor() Object.getOwnPropertyDescriptor()
::getOwnPropertyNames() Object.getOwnPropertyNames()
::getOwnPropertySymbols() Object.getOwnPropertySymbols()
::getPrototype() Object.getPrototypeOf()
::is() Object.is()
::isExtensible() Object.isExtensible()
::isFrozen() Object.isFrozen()
::isSealed() Object.isSealed()
::keys() Object.keys()
::observe() Object.observe()
::preventExtensions() Object.preventExtensions()
::seal() Object.seal()
::setPrototype() Object.setPrototypeOf()

Symbol

Bound Form Native Form
::toSymbol() [1] Symbol.for()
::key() Symbol.keyFor()

Number

Bound Form Native Form
::isFinite() Number.isFinite()
::isInteger() Number.isInteger()
::isNaN() Number.isNaN()
::isSafeInteger() Number.isSafeInteger()
::toFloat() [1] Number.parseFloat()
::toInt() [1] Number.parseInt()

Math

Bound Form Native Form
::abs() Math.abs()
::acos() Math.acos()
::acosh() Math.acosh()
::asin() Math.asin()
::asinh() Math.asinh()
::atan() Math.atan()
::atan2() Math.atan2()
::atanh() Math.atanh()
::cbrt() Math.cbrt()
::ceil() Math.ceil()
::clz32() Math.clz32()
::cos() Math.cos()
::cosh() Math.cosh()
::exp() Math.exp()
::expm1() Math.expm1()
::floor() Math.floor()
::fround() Math.fround()
::hypot() Math.hypot()
::imul() Math.imul()
::log() Math.log()
::log10() Math.log10()
::log1p() Math.log1p()
::log2() Math.log2()
::max() Math.max()
::min() Math.min()
× Math.pow() [2]
× Math.random()
::round() Math.round()
::sign() Math.sign()
::sin() Math.sin()
::sinh() Math.sinh()
::sqrt() Math.sqrt()
::tan() Math.tan()
::tanh() Math.tanh()
::trunc() Math.trunc()

Date

Bound Form Native Form
× Date.UTC()
× Date.now()
::toUnixOffset() [1] Date.parse()

Array

Bound Form Native Form
× Array.from()
× Array.of()

ArrayBuffer

JSON

Native Form Bound Form
JSON.parse() ::toObject() [1]
JSON.stringify() ::toJSON() [1]
Notes:
  1. Bound methods whose names start with "to..." are to be applied to strings (with the exception of ::toJSON() which can be applied to a variety of data types)
  2. Please use the exponentiation operator ** instead

License

MIT © G. Kay Lee

bound-native-methods's People

Contributors

pnowak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bound-native-methods's Issues

Wouldn't partials be better than virtual methods?

Compare:

// ES7

getPlayers()::map(x => x.character())

// ES6

let _val
_val = getPlayers()
_val = map.call(_val, x => x.character())

With:

// ES7

getPlayers()::map(x => x.character())

// ES6

let _val
_val = getPlayers()
_val = map(_val, x => x.character())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.