API Reference
Functions

Functions

The @ibnlanre/builder package exports a set of functions and types for creating and manipulating the builder object. This page documents the public API of the package.

createBuilder

The createBuilder function is used to create a builder object from a register. The function takes two arguments: a register object and an options object that includes a list of prefixes and the type of separator to use. It then returns a builder object.

Signature

function createBuilder<
  Register extends Dictionary,
  const Prefix extends string[] = [],
  const Separator extends string = ".",
>(
  register: Register,
  options?: {
    prefixes?: Prefix;
    separator?: Separator;
  }
): Builder<Register, Prefix, Separator>;

Parameters

  • register - The register object to create the builder object from.
  • [options.prefixes] - An optional array of prefixes to associate with the builder object.
  • [options.separator] - An optional string to use as a separator when joining the prefixes and keys.

Returns

A builder object with the keys and values of the register object.

Example

const register = {
  location: (id: number) => `/location/${id}`,
  address: {
    country: 'Nigeria',
  },
};
 
const builder = createBuilder(register, {
  prefix: ["root", "node"],
  separator: "/"
});