GExtend Object Utility

0.8.0 · abandoned · verified Tue Apr 21

GExtend is a concise utility module designed for robust object extension, supporting both Node.js and browser environments. The package, currently at version 0.8.0, provides a flexible `extend` function to merge properties from multiple source objects into a target object, analogous to `jQuery.extend` or `Object.assign`. It includes specialized methods like `extend.only` for selective property merging, `extend.shim` to safely wrap objects (e.g., `console`) without direct modification, and `extend.unshim` for reverting shims, making it suitable for creating configurable and insulated class instances. Despite its utility, the project appears to be largely unmaintained, with its last recorded release history updates dating back to 2019. Its primary distribution method and usage patterns predate modern JavaScript module conventions, relying heavily on CommonJS and mentioning Bower for frontend integration.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the core object extension functionality, showing how to merge default configuration with user-provided options to create a final, immutable configuration object for a `connect` function.

const extend = require('gextend');

const DEFAULTS = {
    port: 9090,
    url: 'http://localhost'
};

function connect(options){
    // Merges options into DEFAULTS, then into a new empty object.
    // The empty object {} ensures DEFAULTS is not mutated.
    let config = extend({}, DEFAULTS, options);
    console.log('Connect to %s:%s', config.url, config.port);
}

// Example usage
connect({
    url: 'http://127.0.0.1'
});

connect({
    port: 8080
});

connect({});

view raw JSON →