or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

arrays.mdassertions.mdcore.mddom.mdevents.mdindex.mdmath.mdobjects.mdstrings.md
tile.json

tessl/npm-google-closure-library

Google's comprehensive JavaScript library providing utilities, DOM manipulation, UI components, and data structures for building scalable web applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/google-closure-library@20230802.0.x

To install, run

npx @tessl/cli install tessl/npm-google-closure-library@20230802.0.0

index.mddocs/

Google Closure Library

Google Closure Library is a comprehensive JavaScript library providing a robust set of utilities, DOM manipulation tools, event handling, UI components, and data structures for building complex and scalable web applications. Used by major Google applications including Gmail, Google Docs, and Google Maps, it offers cross-browser compatibility, extensive testing frameworks, and optimized performance for enterprise-scale development.

Package Information

  • Package Name: google-closure-library
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install google-closure-library

Core Imports

The library uses a unique module system with goog.require() and goog.provide():

Node.js Bootstrap:

require('google-closure-library/closure/goog/bootstrap/nodejs');

Core Base System:

// After bootstrap, use the goog namespace
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.events');

Basic Usage

// Bootstrap the library for Node.js
require('google-closure-library/closure/goog/bootstrap/nodejs');

// Require needed modules
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.array');

// DOM manipulation
const element = goog.dom.getElement('myDiv');
goog.dom.setTextContent(element, 'Hello Closure!');

// Array utilities
const numbers = [1, 2, 3, 4, 5];
const doubled = goog.array.map(numbers, n => n * 2);
const evens = goog.array.filter(doubled, n => n % 2 === 0);

// Event handling
goog.events.listen(element, 'click', function(e) {
    console.log('Element clicked!');
});

Architecture

Google Closure Library is built around several key architectural principles:

  • Module System: Uses goog.provide() and goog.require() for dependency management
  • Namespace Organization: All functionality organized under the goog namespace with logical sub-namespaces
  • Cross-browser Compatibility: Provides consistent APIs across different browser environments
  • Debug Support: Extensive debugging and assertion capabilities for development
  • Component Architecture: UI components follow a consistent inheritance and event-driven pattern
  • Type System: Extensive use of JSDoc for type annotations and compile-time checking

Capabilities

Core Foundation

The fundamental module system, object utilities, type checking, and class inheritance system that powers the entire library.

// Module system
goog.provide(name);
goog.require(name);

// Type checking
goog.isDefAndNotNull(val);
goog.isFunction(val);
goog.isObject(val);
goog.isArray(val);
goog.isString(val);

// Class system
goog.inherits(childCtor, parentCtor);
goog.bind(fn, selfObj, ...args);

Core Foundation

Array Utilities

Comprehensive collection of array manipulation functions including iteration, search, modification, sorting, and set operations.

// Iteration
goog.array.forEach(arr, f, opt_obj);
goog.array.map(arr, f, opt_obj);
goog.array.filter(arr, f, opt_obj);

// Search and access
goog.array.indexOf(arr, obj, opt_fromIndex);
goog.array.find(arr, f, opt_obj);
goog.array.contains(arr, obj);

// Modification
goog.array.insert(arr, obj);
goog.array.remove(arr, obj);
goog.array.removeAt(arr, i);

Array Utilities

DOM Manipulation

Powerful DOM manipulation utilities for element access, creation, content management, and tree traversal with cross-browser compatibility.

// Element access
goog.dom.getElement(element);
goog.dom.getElementsByClass(className, opt_el);
goog.dom.$(id);

// Element creation
goog.dom.createElement(tagName);
goog.dom.createDom(tagName, opt_attributes, ...var_args);

// Content manipulation
goog.dom.setTextContent(node, text);
goog.dom.appendChild(parent, child);
goog.dom.removeNode(node);

DOM Manipulation

String Processing

Extensive string utilities for testing, transformation, case conversion, manipulation, comparison, and escaping operations.

// String testing
goog.string.isEmpty(str);
goog.string.isEmptyOrWhitespace(str);
goog.string.startsWith(str, prefix);
goog.string.endsWith(str, suffix);

// String transformation
goog.string.trim(str);
goog.string.toCamelCase(str);
goog.string.htmlEscape(str);
goog.string.repeat(string, length);

String Processing

Event System

Comprehensive event handling system with listening, dispatching, and management capabilities for both DOM and custom events.

// Event listening
goog.events.listen(src, type, listener, opt_options, opt_handler);
goog.events.listenOnce(src, type, listener, opt_options, opt_handler);
goog.events.unlisten(src, type, listener, opt_options, opt_handler);

// Event dispatching
goog.events.dispatchEvent(src, e);

// Event classes
goog.events.Event;
goog.events.BrowserEvent;
goog.events.EventTarget;

Event System

Assertions & Debugging

Runtime assertion system with type checking, existence verification, and debugging utilities for development and testing.

// Basic assertions
goog.asserts.assert(condition, opt_message, ...var_args);
goog.asserts.fail(opt_message, ...var_args);

// Type assertions
goog.asserts.assertNumber(value, opt_message, ...var_args);
goog.asserts.assertString(value, opt_message, ...var_args);
goog.asserts.assertFunction(value, opt_message, ...var_args);
goog.asserts.assertArray(value, opt_message, ...var_args);

Assertions & Debugging

Mathematical Operations

Mathematical utilities including basic functions, coordinate systems, geometric calculations, and range operations.

// Basic math
goog.math.clamp(value, min, max);
goog.math.lerp(a, b, x);
goog.math.randomInt(a);

// Coordinate classes
goog.math.Coordinate;
goog.math.Size;
goog.math.Rect;
goog.math.Box;

Mathematical Operations

Object Utilities

Object manipulation utilities including iteration, property management, comparison, cloning, and extension operations.

// Object iteration
goog.object.forEach(obj, f, opt_obj);
goog.object.map(obj, f, opt_obj);
goog.object.filter(obj, f, opt_obj);

// Object manipulation
goog.object.getKeys(obj);
goog.object.getValues(obj);
goog.object.clone(obj);
goog.object.extend(target, ...var_args);

Object Utilities

Types

/**
 * Global goog namespace
 */
interface goog {
  // Core module system
  provide(name: string): void;
  require(name: string): void;
  
  // Global constants
  DEBUG: boolean;
  LOCALE: string;
  
  // Type checking functions
  isDefAndNotNull(val: any): boolean;
  isFunction(val: any): boolean;
  isObject(val: any): boolean;
  isArray(val: any): boolean;
  isString(val: any): boolean;
  isNumber(val: any): boolean;
  isBoolean(val: any): boolean;
}