Installations
npm install ts-class-autobind
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.18.2
NPM Version
6.14.5
Score
49
Supply Chain
83.4
Quality
69.7
Maintenance
25
Vulnerability
96.1
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
DavidArutiunian
Download Statistics
Total Downloads
7,230
Last Day
1
Last Week
22
Last Month
93
Last Year
615
GitHub Statistics
4 Stars
102 Commits
1 Watching
7 Branches
1 Contributors
Bundle Size
1.10 kB
Minified
616.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.3.2
Package Id
ts-class-autobind@0.3.2
Unpacked Size
52.90 kB
Size
12.76 kB
File Count
37
NPM Version
6.14.5
Node Version
12.18.2
Total Downloads
Cumulative downloads
Total Downloads
7,230
Last day
-50%
1
Compared to previous day
Last week
-37.1%
22
Compared to previous week
Last month
257.7%
93
Compared to previous month
Last year
-7.2%
615
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Method auto-bind for TypeScript
Based on class-autobind package.
This package provides a single function, autobind
, for use within a constructor to bind all methods to the instance itself.
For example, this allows us to pass a method to an event handler element.addEventListener('click', this.onClick)
and be sure the onClick
method will always be called with the right context.
Note: This has some specific logic for React, but could be used in any project.
Requirements
TypeScript 3.0 or higher
Installation:
npm install --save ts-class-autobind
Usage:
1import { autobind } from "ts-class-autobind"; 2 3class MyComponent extends React.Component { 4 constructor() { 5 super(...arguments); 6 autobind(this); 7 } 8 render() { 9 return <button onClick={this.onClick}>Click Me</button>; 10 } 11 onClick() { 12 console.log("Button Clicked"); 13 } 14}
Advanced Usage:
If your component will possibly be subclassed (you really should not do this, but some third-party libraries like react-css-modules do so) then you will need to specify which prototype will be the source of methods that are to be automatically bound.
1import { autobind } from "ts-class-autobind"; 2 3class MyComponent extends React.Component { 4 constructor() { 5 super(...arguments); 6 autobind(this, MyComponent.prototype); // Note the second parameter. 7 } 8 render() { 9 /* ... */ 10 } 11} 12 13class MySubClassedComponent extends MyComponent { 14 /* This is probably a very bad idea. */ 15}
License
This software is BSD Licensed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: ISC License: LICENSE.md:0
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 28 are checked with a SAST tool
Score
2
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More