Gathering detailed insights and metrics for @poppinss/macroable
Gathering detailed insights and metrics for @poppinss/macroable
Gathering detailed insights and metrics for @poppinss/macroable
Gathering detailed insights and metrics for @poppinss/macroable
npm install @poppinss/macroable
Update dependencies
Published on 17 Sept 2024
Update dependencies
Published on 28 Mar 2024
Updating dependencies
Published on 15 Dec 2023
Bundle using TSUP and publish under latest tag
Published on 14 Oct 2023
Update dependencies
Published on 23 Sept 2023
Update dependencies
Published on 29 Jun 2023
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
36 Stars
93 Commits
2 Forks
7 Watching
2 Branches
3 Contributors
Updated on 10 Oct 2024
TypeScript (97.82%)
Shell (1.12%)
JavaScript (1.06%)
Cumulative downloads
Total Downloads
Last day
-1.6%
9,999
Compared to previous day
Last week
3%
57,685
Compared to previous week
Last month
8.1%
241,265
Compared to previous month
Last year
4,712%
1,565,692
Compared to previous year
Extend classes from outside in using Macros and getters
Macroable offers a simple API for adding properties and getters to the class prototype. You might not even need this package, if you are happy writing Object.defineProperty
calls yourself.
Install the package from npm packages registry as follows.
1npm i @poppinss/macroable 2 3# yarn lovers 4yarn add @poppinss/macroable
And import the Macroable
class.
1import Macroable from '@poppinss/macroable' 2export class Route extends Macroable {}
Now, you can add properties to the Route class from outside-in. This is usually needed, when you want the consumer of your classes to be able to extend them by adding custom properties.
Getters are added to the class prototype directly.
1Route.macro('head', function (uri, callback) { 2 return this.route(['HEAD'], uri, callback) 3})
And now, you can will be use the head
method from an instance of the Route
class.
1const route = new Route() 2route.head('/', () => {})
Adding a macro is same as writing the following code in JavaScript.
1Route.prototype.head = function () { 2}
Getters are added to the class prototype using the Object.defineProperty
. The implementation of a getter is always a function.
1Route.getter('version', function () { 2 return 'v1' 3})
And now access the version as follows.
1const route = new Route() 2route.version // v1
Adding a getter is same as writing the following code in JavaScript.
1Object.defineProperty(Route.prototype, 'version', { 2 get() { 3 const value = callback() 4 return value 5 }, 6 configurable: false, 7 enumerable: false, 8})
Singleton getters are also defined on the class prototype. However, their values are cached after the first access.
1const singleton = true 2 3Mysql.getter('version', function () { 4 return this.config.driver.split('-')[1] 5}, singleton)
Adding a singleton getter is same as writing the following code in JavaScript.
1Object.defineProperty(Mysql.prototype, 'version', {
2 get() {
3 const value = callback()
4
5 // Cache value on the class instance
6 Object.defineProperty(this, 'version', {
7 configurable: false,
8 enumerable: false,
9 value: value,
10 writable: false,
11 })
12
13 return value
14 },
15 configurable: false,
16 enumerable: false,
17})
You will have to use module augmentation in order to define the types for the dynamically added properties.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
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