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
Extend classes from outside in using Macros and getters
npm install @poppinss/macroable
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
100
Quality
81.3
Maintenance
100
Vulnerability
100
License
Updated dependencies
Updated on Dec 27, 2024
Update dependencies
Updated on Sep 17, 2024
Update dependencies
Updated on Mar 28, 2024
Updating dependencies
Updated on Dec 15, 2023
Bundle using TSUP and publish under latest tag
Updated on Oct 14, 2023
Update dependencies
Updated on Sep 23, 2023
TypeScript (98.93%)
JavaScript (1.07%)
Total Downloads
3,534,854
Last Day
6,688
Last Week
80,843
Last Month
343,828
Last Year
3,088,490
MIT License
36 Stars
98 Commits
2 Forks
6 Watchers
2 Branches
3 Contributors
Updated on Dec 27, 2024
Minified
Minified + Gzipped
Latest Version
1.0.4
Package Id
@poppinss/macroable@1.0.4
Unpacked Size
9.64 kB
Size
3.76 kB
File Count
5
NPM Version
10.8.2
Node Version
20.18.1
Published on
Dec 27, 2024
Cumulative downloads
Total Downloads
Last Day
32.9%
6,688
Compared to previous day
Last Week
-6.4%
80,843
Compared to previous week
Last Month
0.7%
343,828
Compared to previous month
Last Year
596%
3,088,490
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.
One of our primary goals is to have a vibrant community of users and contributors who believes in the principles of the framework.
We encourage you to read the contribution guide before contributing to the framework.
In order to ensure that the community is welcoming to all, please review and abide by the Code of Conduct.
Poppinss macroable is open-sourced software licensed under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 0/30 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
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 2025-06-23
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