PrettyType
raw JSON → 2.0.0 verified Fri May 01 auth: no javascript maintenance
Multi-platform ES5 coding patterns and base super-prototypes for write-once, run-and-test everywhere (AngularJS, RequireJS, Node.js). Version 2.0.0 targets ES5 with no transpiler dependency, supporting Node 0.10.x+, AngularJS 1.x, RequireJS/AMD, and modern browsers. It provides reusable base prototypes, module patterns, and dependency injection for server/browser logic without build steps. Differentiators: native ES5 (no transpiler), supports multiple module systems without browserify, and includes supertype constructors for prototypal inheritance. Release cadence is low (stable, not actively updated).
Common errors
error Cannot find module 'prettytype' ↓
cause Package not installed or path incorrect.
fix
Run 'npm install prettytype' and ensure node_modules is present.
error TypeError: PrettyType.extend is not a function ↓
cause Importing default export incorrectly in CommonJS.
fix
Use 'const PrettyType = require('prettytype')' (no destructuring).
error ReferenceError: define is not defined ↓
cause AMD code running in non-browser env without RequireJS.
fix
Check if define exists before using: if (typeof define === 'function' && define.amd) { ... }
Warnings
gotcha ES5-only: Polyfills required for ES6+. No Promise, Map, Set, or arrow functions. ↓
fix Use ES5 polyfills (e.g., core-js) if running in modern environments that drop ES5 support.
deprecated AngularJS 1.x support may be deprecated; Angular 2+ not compatible. ↓
fix For Angular 2+, wrap PrettyType in Angular services.
gotcha Browser global leak if not loaded via AMD or CommonJS; adds to window object. ↓
fix Always load via AMD/CommonJS or wrap in IIFE.
breaking v2.0.0 changed export structure from v1; named exports replaced default object. ↓
fix Update imports: use require('prettytype') instead of require('prettytype').PrettyType.
Install
npm install prettytype yarn add prettytype pnpm add prettytype Imports
- PrettyType wrong
const { PrettyType } = require('prettytype')correctimport PrettyType from 'prettytype' - BaseProto wrong
const BaseProto = require('prettytype').BaseProtocorrectimport { BaseProto } from 'prettytype' - SuperProto wrong
var SuperProto = require('prettytype').SuperProtocorrectimport { SuperProto } from 'prettytype'
Quickstart
// Example: Using PrettyType to create a multi-platform module
// Assume prettytype is installed via npm or included in browser
const PrettyType = require('prettytype');
// Define a simple prototype using PrettyType patterns
const MyApp = PrettyType.extend({
constructor: function(config) {
this.config = config || {};
this.name = this.config.name || 'default';
},
init: function() {
console.log('MyApp initialized with name:', this.name);
return this;
},
greet: function() {
return 'Hello from ' + this.name;
}
});
// Create an instance
const app = new MyApp({ name: 'test' });
app.init();
console.log(app.greet());
// Export for multiple platforms (if needed)
if (typeof define === 'function' && define.amd) {
define(function() { return MyApp; });
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = MyApp;
}