Google Closure Library

20230802.0.0 · active · verified Sun Apr 19

Google Closure Library is a comprehensive, low-level JavaScript library developed by Google for building complex, highly performant, and scalable web applications. It serves as the foundation for many of Google's own web properties, including Gmail, Google Docs, and Google Maps. The library is not a typical npm package with standard ES module exports but rather provides its own module system (`goog.require`, `goog.provide`) built around a global `goog` object. It ships with a vast array of utilities covering DOM manipulation, UI components, networking, internationalization, data structures, and more. The current stable version is 20230802.0.0, and it follows a roughly monthly to bi-monthly release cadence, providing continuous updates and improvements, often tied to internal Google development cycles. Its key differentiators include its robust type system (when used with Closure Compiler), extensive cross-browser compatibility layers, and a strong emphasis on performance and security, making it suitable for large-scale enterprise applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize Closure Library in a Node.js environment, load specific components using `goog.require`, and use them to perform a SHA-1 hash operation.

require('google-closure-library');

goog.require('goog.crypt.Sha1');
goog.require('goog.array');

const sha1 = new goog.crypt.Sha1();
const data = 'Hello, Closure Library!';
sha1.update(data);
const hash = sha1.digest();

console.log(`SHA-1 hash of '${data}': ${goog.array.map(hash, byte => byte.toString(16).padStart(2, '0')).join('')}`);

// Example of a utility that might not be available directly in Node.js
// goog.require('goog.dom');
// console.log(goog.dom.getWindow()); // This would typically only work in a browser environment

view raw JSON →