FBJS Utilities

3.0.5 · maintenance · verified Sun Apr 19

FBJS (Facebook JavaScript) is a collection of utility libraries developed by Facebook primarily for internal consumption within their JavaScript projects, such as React and Relay. Currently at version 3.0.5, this package does not follow strict semantic versioning and APIs may change or disappear without public notice. It is explicitly not designed for broader public use, and external projects consuming it should anticipate instability and a lack of support. Its core purpose is to facilitate code sharing across Facebook's internal monorepo, leveraging a custom `@providesModule` system that is transformed into CommonJS `require('fbjs/lib/moduleName')` paths during a build step. There is no stated public release cadence, as its releases are tied directly to Facebook's internal development needs.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates direct CommonJS `require` usage of core FBJS utilities like `emptyFunction`, `warning`, `invariant`, and `identity`, illustrating their typical functionality.

// This example demonstrates direct CommonJS usage of FBJS utilities.
// Note: FBJS is primarily intended for internal Facebook projects and
// is not guaranteed to follow semver or provide stable public APIs.

const emptyFunction = require('fbjs/lib/emptyFunction');
const warning = require('fbjs/lib/warning');
const invariant = require('fbjs/lib/invariant');
const identity = require('fbjs/lib/identity');

console.log('Calling emptyFunction:', emptyFunction()); // Should print undefined

let shouldWarn = true;
warning(
  !shouldWarn, // Condition for warning to trigger (true means no warning, false means warning)
  'This is a development warning from FBJS. Condition was %s.', // Message
  shouldWarn // Args for message formatting
);

// invariant example (will throw if condition is false)
try {
  const value = null;
  invariant(value != null, 'Value must not be null or undefined.');
  console.log('Value is:', value);
} catch (e) {
  console.error('Invariant failed:', e.message);
}

console.log('Identity of 123 is:', identity(123)); // Should print 123

view raw JSON →