├── .babelrc
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── deploy
├── gulpfile.babel.js
├── package.json
└── source
├── array-buffer.js
├── array.js
├── date.js
├── function-generator.js
├── index.js
├── json.js
├── math.js
├── number.js
├── object.js
└── symbol.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "experimental": true,
3 | "stage": 0,
4 | "loose": "all",
5 | "optional": [
6 | "minification.inlineExpressions"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 |
3 | root = true
4 |
5 | [*]
6 | charset = utf-8
7 | indent_style = space
8 | indent_size = 2
9 | end_of_line = lf
10 | trim_trailing_whitespace = true
11 | insert_final_newline = true
12 |
13 | [*.md]
14 | trim_trailing_whitespace = false
15 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # http://git-scm.com/docs/gitattributes
2 |
3 | * text=auto
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # http://git-scm.com/docs/gitignore
2 |
3 | /*.js
4 | !/gulpfile.babel.js
5 |
6 | node_modules
7 | *.log
8 | .tmp
9 | .DS_Store
10 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # https://docs.npmjs.com/misc/developers
2 |
3 | *
4 | !.gitignore
5 | !LICENSE
6 |
7 | !/*.js
8 | /gulpfile.babel.js
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 G. Kay Lee
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Bound Native Methods
2 | ====================
3 |
4 | This library exports a collection of bound native [**virtual methods**](http://babeljs.io/blog/2015/05/14/function-bind/#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**](https://github.com/zenparsing/es-function-bind).
5 |
6 | Install
7 | -------
8 |
9 | ```bash
10 | $ npm install bound-native-methods
11 | ```
12 |
13 | Usage
14 | -----
15 |
16 | ```javascript
17 | import * from 'bound-native-methods';
18 |
19 | // Or, be more specific and cut down the build size: //
20 |
21 | import {assign, keys} from 'bound-native-methods/object';
22 | ```
23 |
24 | ```javascript
25 | 0::isInteger();
26 | // true
27 | ```
28 |
29 | ```javascript
30 | [3, 6, 9]::max()::is(9);
31 | // true
32 | ```
33 |
34 | ```javascript
35 | {'2015-06-01T15:30:00.000Z': 300}::assign({'2015-07-01T15:30:00.000Z': 42})
36 | ::keys()
37 | .map(x => x::toUnixOffset())
38 | ::toJSON();
39 | // [1433172600000,1435764600000]
40 | ```
41 |
42 | API
43 | ---
44 |
45 | Most static methods have been exported as is, but a few have been renamed or excluded to better fit the context:
46 |
47 | #### Object
48 |
49 | | Bound Form | Native Form |
50 | | ---------- | ----------- |
51 | | ::assign() | Object.assign() |
52 | | ::create() | Object.create() |
53 | | ::defineProperties() | Object.defineProperties() |
54 | | ::defineProperty() | Object.defineProperty() |
55 | | ::freeze() | Object.freeze() |
56 | | ::getOwnPropertyDescriptor() | Object.getOwnPropertyDescriptor() |
57 | | ::getOwnPropertyNames() | Object.getOwnPropertyNames() |
58 | | ::getOwnPropertySymbols() | Object.getOwnPropertySymbols() |
59 | | ***::getPrototype()*** | ***Object.getPrototypeOf()*** |
60 | | ::is() | Object.is() |
61 | | ::isExtensible() | Object.isExtensible() |
62 | | ::isFrozen() | Object.isFrozen() |
63 | | ::isSealed() | Object.isSealed() |
64 | | ::keys() | Object.keys() |
65 | | ::observe() | Object.observe() |
66 | | ::preventExtensions() | Object.preventExtensions() |
67 | | ::seal() | Object.seal() |
68 | | ***::setPrototype()*** | ***Object.setPrototypeOf()*** |
69 |
70 | #### Symbol
71 |
72 | | Bound Form | Native Form |
73 | | ---------- | ----------- |
74 | | ***::toSymbol()*** [1] | ***Symbol.for()*** |
75 | | ***::key()*** | ***Symbol.keyFor()*** |
76 |
77 | #### Number
78 |
79 | | Bound Form | Native Form |
80 | | ---------- | ----------- |
81 | | ::isFinite() | Number.isFinite() |
82 | | ::isInteger() | Number.isInteger() |
83 | | ::isNaN() | Number.isNaN() |
84 | | ::isSafeInteger() | Number.isSafeInteger() |
85 | | ***::toFloat()*** [1] | ***Number.parseFloat()*** |
86 | | ***::toInt()*** [1] | ***Number.parseInt()*** |
87 |
88 | #### Math
89 |
90 | | Bound Form | Native Form |
91 | | ---------- | ----------- |
92 | | ::abs() | Math.abs() |
93 | | ::acos() | Math.acos() |
94 | | ::acosh() | Math.acosh() |
95 | | ::asin() | Math.asin() |
96 | | ::asinh() | Math.asinh() |
97 | | ::atan() | Math.atan() |
98 | | ::atan2() | Math.atan2() |
99 | | ::atanh() | Math.atanh() |
100 | | ::cbrt() | Math.cbrt() |
101 | | ::ceil() | Math.ceil() |
102 | | ::clz32() | Math.clz32() |
103 | | ::cos() | Math.cos() |
104 | | ::cosh() | Math.cosh() |
105 | | ::exp() | Math.exp() |
106 | | ::expm1() | Math.expm1() |
107 | | ::floor() | Math.floor() |
108 | | ::fround() | Math.fround() |
109 | | ::hypot() | Math.hypot() |
110 | | ::imul() | Math.imul() |
111 | | ::log() | Math.log() |
112 | | ::log10() | Math.log10() |
113 | | ::log1p() | Math.log1p() |
114 | | ::log2() | Math.log2() |
115 | | ::max() | Math.max() |
116 | | ::min() | Math.min() |
117 | | ***×*** | ***Math.pow()*** [2] |
118 | | ***×*** | ***Math.random()*** |
119 | | ::round() | Math.round() |
120 | | ::sign() | Math.sign() |
121 | | ::sin() | Math.sin() |
122 | | ::sinh() | Math.sinh() |
123 | | ::sqrt() | Math.sqrt() |
124 | | ::tan() | Math.tan() |
125 | | ::tanh() | Math.tanh() |
126 | | ::trunc() | Math.trunc() |
127 |
128 | #### Date
129 |
130 | | Bound Form | Native Form |
131 | | ---------- | ----------- |
132 | | ***×*** | ***Date.UTC()*** |
133 | | ***×*** | ***Date.now()*** |
134 | | ***::toUnixOffset()*** [1] | ***Date.parse()*** |
135 |
136 | #### Array
137 |
138 | | Bound Form | Native Form |
139 | | ---------- | ----------- |
140 | | × | Array.from() |
141 | | × | Array.of() |
142 |
143 | #### ArrayBuffer
144 |
145 | #### JSON
146 |
147 | | Native Form | Bound Form |
148 | | ----------- | ---------- |
149 | | JSON.parse() | ::toObject() [1] |
150 | | JSON.stringify() | ::toJSON() [1] |
151 |
152 | > ###### Notes:
153 | > 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)
154 | > 2. Please use the exponentiation operator `**` instead
155 |
156 | License
157 | -------
158 |
159 | MIT © G. Kay Lee
160 |
--------------------------------------------------------------------------------
/deploy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | git flow release start $1
4 | npm --no-git-tag-version version $1
5 | git commit -am "Bump version to $1"
6 | git flow release finish $1
7 | git push --all origin
8 | git push --tag origin
9 | npm publish
10 |
--------------------------------------------------------------------------------
/gulpfile.babel.js:
--------------------------------------------------------------------------------
1 | import Gulp from 'gulp';
2 | import GulpLoadPlugins from 'gulp-load-plugins';
3 |
4 | const _ = GulpLoadPlugins();
5 |
6 | Gulp.task('build',
7 | () => Gulp.src([
8 | 'source/*.js'
9 | ])
10 | .pipe(_.babel())
11 | .pipe(Gulp.dest('.'))
12 | );
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bound-native-methods",
3 | "version": "0.1.6",
4 | "description": "Bound native virtual methods to be used together with ES7 :: bind operator.",
5 | "author": "G. Kay Lee ",
6 | "scripts": {
7 | "setup": "npm cache clean && npm install",
8 | "update": "rm -rf node_modules && npm-check-updates -u && npm run setup",
9 | "build": "gulp build",
10 | "deploy": "npm run build && ./deploy"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "https://github.com/gsklee/bound-native-methods"
15 | },
16 | "keywords": [
17 | "virtual method",
18 | "method extraction",
19 | "function bind",
20 | "bind operator",
21 | "bind",
22 | "es6",
23 | "es7",
24 | "babel"
25 | ],
26 | "dependencies": {},
27 | "devDependencies": {
28 | "babel": "^5.5.3",
29 | "gulp": "^3.9.0",
30 | "gulp-load-plugins": "^0.10.0",
31 | "gulp-babel": "^5.1.0"
32 | },
33 | "engines": {
34 | "iojs": ">=2.0.0"
35 | },
36 | "license": "MIT"
37 | }
38 |
--------------------------------------------------------------------------------
/source/array-buffer.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(ArrayBuffer, [
4 | 'isView',
5 | 'transfer'
6 | ]);
7 |
--------------------------------------------------------------------------------
/source/array.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(Array, [
4 | 'isArray',
5 | 'observe'
6 | ]);
7 |
--------------------------------------------------------------------------------
/source/date.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(Date, [
4 | 'parse'
5 | ], {
6 | parse: 'toUnixOffset'
7 | });
8 |
--------------------------------------------------------------------------------
/source/function-generator.js:
--------------------------------------------------------------------------------
1 | export default (object, names, rename = {}) =>
2 | names.reduce((m, name) => {
3 | m[rename[name] || name] = function (...s) {
4 | return this.constructor === Array && object === Math ? object[name](...this, ...s) :
5 | object[name](this, ...s);
6 | };
7 |
8 | return m;
9 | }, {});
10 |
--------------------------------------------------------------------------------
/source/index.js:
--------------------------------------------------------------------------------
1 | export * from './object';
2 | export * from './symbol.js';
3 | export * from './number.js';
4 | export * from './math.js';
5 | export * from './date.js';
6 | export * from './array.js';
7 | export * from './array-buffer.js';
8 | export * from './json.js';
9 |
--------------------------------------------------------------------------------
/source/json.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(JSON, [
4 | 'parse',
5 | 'stringify'
6 | ], {
7 | parse: 'toObject',
8 | stringify: 'toJSON'
9 | });
10 |
--------------------------------------------------------------------------------
/source/math.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(Math, [
4 | 'abs',
5 | 'acos',
6 | 'acosh',
7 | 'asin',
8 | 'asinh',
9 | 'atan',
10 | 'atan2',
11 | 'atanh',
12 | 'cbrt',
13 | 'ceil',
14 | 'clz32',
15 | 'cos',
16 | 'cosh',
17 | 'exp',
18 | 'expm1',
19 | 'floor',
20 | 'fround',
21 | 'hypot',
22 | 'imul',
23 | 'log',
24 | 'log10',
25 | 'log1p',
26 | 'log2',
27 | 'max',
28 | 'min',
29 | 'round',
30 | 'sign',
31 | 'sin',
32 | 'sinh',
33 | 'sqrt',
34 | 'tan',
35 | 'tanh',
36 | 'trunc'
37 | ]);
38 |
--------------------------------------------------------------------------------
/source/number.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(Number, [
4 | 'isFinite',
5 | 'isInteger',
6 | 'isNaN',
7 | 'isSafeInteger',
8 | 'parseFloat',
9 | 'parseInt'
10 | ], {
11 | parseFloat: 'toFloat',
12 | parseInt: 'toInt'
13 | });
14 |
--------------------------------------------------------------------------------
/source/object.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(Object, [
4 | 'assign',
5 | 'create',
6 | 'defineProperties',
7 | 'defineProperty',
8 | 'freeze',
9 | 'getOwnPropertyDescriptor',
10 | 'getOwnPropertyNames',
11 | 'getOwnPropertySymbols',
12 | 'getPrototypeOf',
13 | 'is',
14 | 'isExtensible',
15 | 'isFrozen',
16 | 'isSealed',
17 | 'keys',
18 | 'preventExtensions',
19 | 'seal',
20 | 'setPrototypeOf'
21 | ], {
22 | getPrototypeOf: 'getPrototype',
23 | setPrototypeOf: 'setPrototype'
24 | });
25 |
--------------------------------------------------------------------------------
/source/symbol.js:
--------------------------------------------------------------------------------
1 | import functionGenerator from './function-generator';
2 |
3 | export default functionGenerator(Symbol, [
4 | 'for',
5 | 'keyFor'
6 | ], {
7 | for: 'toSymbol',
8 | keyFor: 'key'
9 | });
10 |
--------------------------------------------------------------------------------