Registry / web-framework / autocreate

autocreate

JSON →
library1.2.0jsnpmunverified

autocreate is a JavaScript utility that allows classes to be called without the `new` keyword, and provides a hook method (`__class_call__`) to customize behavior when invoked as a plain function. Current stable version is 1.2.0, with a low release cadence. It supports ES7/Babel decorators, TypeScript, CoffeeScript, and plain JavaScript, targeting ES5/ES6+ environments. Unlike similar libraries (e.g., `newless`), autocreate handles inheritance, static properties, and non-enumerable descriptors without external dependencies. It provides both decorator and manual wrapping patterns for maximum flexibility.

npm install autocreate
INSTALL
IMPORT
SIG · AUTOCREATE
A
autocreate
web-frameworkjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const auto = require('autocreate');
import auto from 'autocreate';
autocreate does not expose an ES module; CommonJS require is the only way to import. For TypeScript, use `import auto = require('autocreate');` or `const auto = require('autocreate')` with `esModuleInterop: false`.
auto
@auto class MyClass { ... }
class MyClass { @auto ... }
The `@auto` decorator must be applied to the class declaration, not inside the class body. For Babel, enable decorators legacy or stage 0. TypeScript requires `experimentalDecorators: true`.
auto (function call)
const MyClass = auto(function MyClass() { ... });
auto(MyClass); // if used before function declaration
In plain JavaScript, pass the function expression/class directly to `auto()`. For named functions, the return value replaces the original reference; do not rely on hoisting with `@auto`.

Demonstrates basic usage of @auto decorator to omit `new`, and custom __class_call__ hook for different behavior when called as function.

const auto = require('autocreate'); @auto class MyClass { constructor(name) { this.name = name; } greet() { return `Hello, ${this.name}!`; } } // Without `new`: const instance = MyClass('World'); console.log(instance.greet()); // Hello, World! // With `new`: const instance2 = new MyClass('Universe'); console.log(instance2.greet()); // Hello, Universe! // Using __class_call__: @auto class Counter { constructor() { this.count = 0; } __class_call__() { return { count: 'function called' }; } } console.log(Counter()); // { count: 'function called' } console.log(new Counter().count); // 0
Debug
Known issues
gotchaThe `@auto` decorator only works with class declarations, not class expressions. Using it on expressions yields undefined behavior.
fix
Use `const MyClass = auto(class { ... })` instead of `@auto` for class expressions.
affects: >=1.0.0
gotchaWhen using `__class_call__`, `this` inside it refers to the prototype, not the constructor or new instance. This surprises many developers.
fix
Access constructor via `this.constructor` or store needed state on the prototype.
affects: >=1.0.0
gotchaautocreate does not support asynchronous constructors. Since the constructor always returns an object, async construction requires external patterns.
fix
Use a static async factory method instead.
affects: >=1.0.0
gotchaInheritance with custom `__class_call__` may not propagate correctly if parent uses `@auto` and child overrides `__class_call__`. The child's `__class_call__` replaces the parent's.
fix
Manually call parent's `__class_call__` from child's if needed.
affects: >=1.0.0
gotchaThe module uses `require('autocreate')` only; no ES module build is provided. Using `import` from an ESM context may fail unless using a bundler.
fix
If using ESM, use `createRequire` from 'module' or a bundler that handles CJS interop.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Using `@auto` on a class that is exported as default and then extended in another module, where the import resolves to the wrapped version twice.
fix
Export the class before applying `@auto`, or use a separate variable to hold the wrapped class.
SyntaxError: Decorators are not supported in this environment
Trying to use `@auto` in an environment that does not support decorators (e.g., plain Node.js without transpilation).
fix
Use the functional form: `const MyClass = auto(MyClass)` after the class definition, or transpile with Babel/TypeScript with decorator support.
TypeError: autocreate is not a function
Attempting to import autocreate as an ES module default import (`import auto from 'autocreate'`) instead of requiring it.
fix
Use `const auto = require('autocreate')` (CommonJS) or configure bundler to handle default exports from CJS.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
autocreate — npm install autocreate · libregistry