[Pkg-javascript-commits] [node-auto-bind] 01/02: Import Upstream version 0.1.0

Shanavas M shanavas-guest at moszumanska.debian.org
Thu Nov 3 19:31:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

shanavas-guest pushed a commit to branch master
in repository node-auto-bind.

commit 7133b9da3424531d49e976573d872ff6551bf328
Author: Shanavas M <shanavas at disroot.org>
Date:   Thu Nov 3 18:47:04 2016 +0000

    Import Upstream version 0.1.0
---
 .editorconfig  | 12 ++++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .travis.yml    |  6 ++++++
 index.js       | 10 ++++++++++
 license        | 21 +++++++++++++++++++++
 package.json   | 38 ++++++++++++++++++++++++++++++++++++++
 readme.md      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test.js        | 19 +++++++++++++++++++
 9 files changed, 158 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..e526ffa
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,6 @@
+language: node_js
+node_js:
+  - '6'
+  - '4'
+  - '0.12'
+  - '0.10'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..555ef2c
--- /dev/null
+++ b/index.js
@@ -0,0 +1,10 @@
+'use strict';
+module.exports = function (self) {
+	Object.getOwnPropertyNames(self.constructor.prototype).forEach(function (key) {
+		var val = self[key];
+
+		if (key !== 'constructor' && typeof val === 'function') {
+			self[key] = val.bind(self);
+		}
+	});
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..4fe1b6c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,38 @@
+{
+  "name": "auto-bind",
+  "version": "0.1.0",
+  "description": "Automatically bind methods to their class instance",
+  "license": "MIT",
+  "repository": "sindresorhus/auto-bind",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "xo && ava"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "auto",
+    "bind",
+    "class",
+    "methods",
+    "method",
+    "automatically",
+    "prototype",
+    "instance",
+    "function",
+    "this",
+    "self"
+  ],
+  "devDependencies": {
+    "ava": "*",
+    "xo": "*"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..4aaf930
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,50 @@
+# auto-bind [![Build Status](https://travis-ci.org/sindresorhus/auto-bind.svg?branch=master)](https://travis-ci.org/sindresorhus/auto-bind)
+
+> Automatically bind methods to their class instance
+
+
+## Install
+
+```
+$ npm install --save auto-bind
+```
+
+
+## Usage
+
+```js
+const autoBind = require('auto-bind');
+
+class Unicorn {
+	constructor(name) {
+		this.name = name;
+		autoBind(this);
+	}
+	message() {
+		return `${this.name} is awesome!`;
+	}
+}
+
+const unicorn = new Unicorn('Rainbow');
+
+// grab the method off the class instance
+const message = unicorn.message;
+
+// still bound to the class instance
+message();
+//=> 'Rainbow is awesome!'
+
+// without `autoBind(this)`, the above would have resulted in
+message();
+//=> Error: Cannot read property 'name' of undefined
+```
+
+
+## Related
+
+- [bind-methods](https://github.com/sindresorhus/bind-methods) - Bind all methods in an object to itself or a specified context
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..b7c83dc
--- /dev/null
+++ b/test.js
@@ -0,0 +1,19 @@
+import test from 'ava';
+import m from './';
+
+test(t => {
+	class Unicorn {
+		constructor(name) {
+			this.name = name;
+			m(this);
+		}
+		message() {
+			return `${this.name} is awesome!`;
+		}
+	}
+
+	const unicorn = new Unicorn('Rainbow');
+	const message = unicorn.message;
+
+	t.is(message(), 'Rainbow is awesome!');
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-auto-bind.git



More information about the Pkg-javascript-commits mailing list