{"id":18978,"library":"autocreate","title":"autocreate","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"git@github.com:pjeby/autocreate","tags":["javascript","class","classes","constructors","decorators","ES6","ES7","new","Babel"],"install":[{"cmd":"npm install autocreate","lang":"bash","label":"npm"},{"cmd":"yarn add autocreate","lang":"bash","label":"yarn"},{"cmd":"pnpm add autocreate","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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`.","wrong":"import auto from 'autocreate';","symbol":"default","correct":"const auto = require('autocreate');"},{"note":"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`.","wrong":"class MyClass { @auto ... }","symbol":"auto","correct":"@auto class MyClass { ... }"},{"note":"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`.","wrong":"auto(MyClass); // if used before function declaration","symbol":"auto (function call)","correct":"const MyClass = auto(function MyClass() { ... });"}],"quickstart":{"code":"const auto = require('autocreate');\n\n@auto\nclass MyClass {\n  constructor(name) {\n    this.name = name;\n  }\n  greet() {\n    return `Hello, ${this.name}!`;\n  }\n}\n\n// Without `new`:\nconst instance = MyClass('World');\nconsole.log(instance.greet()); // Hello, World!\n\n// With `new`:\nconst instance2 = new MyClass('Universe');\nconsole.log(instance2.greet()); // Hello, Universe!\n\n// Using __class_call__:\n@auto\nclass Counter {\n  constructor() {\n    this.count = 0;\n  }\n  __class_call__() {\n    return { count: 'function called' };\n  }\n}\n\nconsole.log(Counter()); // { count: 'function called' }\nconsole.log(new Counter().count); // 0","lang":"typescript","description":"Demonstrates basic usage of @auto decorator to omit `new`, and custom __class_call__ hook for different behavior when called as function."},"warnings":[{"fix":"Use `const MyClass = auto(class { ... })` instead of `@auto` for class expressions.","message":"The `@auto` decorator only works with class declarations, not class expressions. Using it on expressions yields undefined behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Access constructor via `this.constructor` or store needed state on the prototype.","message":"When using `__class_call__`, `this` inside it refers to the prototype, not the constructor or new instance. This surprises many developers.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a static async factory method instead.","message":"autocreate does not support asynchronous constructors. Since the constructor always returns an object, async construction requires external patterns.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually call parent's `__class_call__` from child's if needed.","message":"Inheritance 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If using ESM, use `createRequire` from 'module' or a bundler that handles CJS interop.","message":"The module uses `require('autocreate')` only; no ES module build is provided. Using `import` from an ESM context may fail unless using a bundler.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.2.0':37 'allow':8 'autocr':1,2,60 'babel':92 'behavior':26 'cadenc':42 'call':12,23 'class':9,22,85,86 'coffeescript':48 'constructor':87 'current':33 'custom':25 'decor':46,76,88 'depend':72 'descriptor':69 'e.g':58 'enumer':68 'environ':54 'es5/es6':53 'es6':89 'es7':90 'es7/babel':45 'extern':71 'flexibl':83 'function':32 'handl':61 'hook':20 'inherit':62 'invok':28 'javascript':5,51,84 'keyword':16 'librari':57 'low':40 'manual':78 'maximum':82 'method':21 'new':15,91 'newless':59 'non':67 'non-enumer':66 'pattern':80 'plain':31,50 'properti':64 'provid':18,74 'releas':41 'similar':56 'stabl':34 'static':63 'support':44 'target':52 'typescript':47 'unlik':55 'util':6 'version':35 'without':13,70 'wrap':79","created_at":"2026-04-25T11:15:23.403920+00:00","updated_at":"2026-04-25T11:15:23.403920+00:00","problems":[{"fix":"Export the class before applying `@auto`, or use a separate variable to hold the wrapped class.","cause":"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.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Use the functional form: `const MyClass = auto(MyClass)` after the class definition, or transpile with Babel/TypeScript with decorator support.","cause":"Trying to use `@auto` in an environment that does not support decorators (e.g., plain Node.js without transpilation).","error":"SyntaxError: Decorators are not supported in this environment"},{"fix":"Use `const auto = require('autocreate')` (CommonJS) or configure bundler to handle default exports from CJS.","cause":"Attempting to import autocreate as an ES module default import (`import auto from 'autocreate'`) instead of requiring it.","error":"TypeError: autocreate is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://autocreate.js.org","github":null,"docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/autocreate","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}