---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../../modules.md) / [operations/content](../index.md) / Library

# Class: Library

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:172](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L172)

Provides an interface for manipulating B2C Commerce content libraries.

Use the static `Library.parse()` factory to create instances from library XML.
The library tree supports filtering, traversal, mutation, and serialization
back to importable XML.

## Example

```typescript
const library = await Library.parse(xmlString);

// Filter to specific pages
library.filter(node => node.id === 'homepage');

// Traverse visible nodes
library.traverse(node => {
  console.log(node.id, node.type);
});

// Serialize back to XML
const xml = await library.toXMLString({ traverseHidden: false });
```

## Properties

### assetQuery

> **assetQuery**: `string`[] = `[]`

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:173](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L173)

***

### tree

> **tree**: [`LibraryNode`](LibraryNode.md)

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:174](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L174)

## Methods

### filter()

> **filter**(`predicate`, `options`): `this`

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:326](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L326)

Filter the library tree by setting hidden flags on root children.

#### Parameters

##### predicate

[`FilterCallback`](../type-aliases/FilterCallback.md)

Return true to keep the node visible

##### options

Filter options

###### recursive?

`boolean` = `false`

#### Returns

`this`

this (for chaining)

***

### getTreeString()

> **getTreeString**(`options`): `string`

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:421](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L421)

Returns a text tree visualization of the library structure.

#### Parameters

##### options

[`TreeStringOptions`](../interfaces/TreeStringOptions.md) = `{}`

Tree string options (traversal and optional colorize function)

#### Returns

`string`

Multi-line tree string

***

### nodes()

> **nodes**(`options`): `Generator`\<[`LibraryNode`](LibraryNode.md)\>

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:301](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L301)

Generator-based depth-first iteration of the library tree.

#### Parameters

##### options

[`TraverseOptions`](../interfaces/TraverseOptions.md) = `{}`

Traversal options

#### Returns

`Generator`\<[`LibraryNode`](LibraryNode.md)\>

#### Yields

LibraryNode for each visited node

#### Example

```typescript
for (const node of library.nodes()) {
  console.log(node.id, node.type);
}
```

***

### promoteToRoot()

> **promoteToRoot**(`node`): `this`

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:352](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L352)

Move a node from its current parent to the root of the library tree.

Useful for exporting individual components that are normally nested under pages.
The node is removed from its original parent's children and added as a root child.

#### Parameters

##### node

[`LibraryNode`](LibraryNode.md)

The node to promote

#### Returns

`this`

this (for chaining)

***

### reset()

> **reset**(): `this`

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:371](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L371)

Reset all hidden flags, making every node visible again.

#### Returns

`this`

this (for chaining)

***

### toJSON()

> **toJSON**(): `Record`\<`string`, `unknown`\>

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:475](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L475)

Returns a JSON-safe representation of the library tree.

#### Returns

`Record`\<`string`, `unknown`\>

***

### toXMLString()

> **toXMLString**(`options`): `Promise`\<`string`\>

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:389](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L389)

Serialize the library back to importable XML.

Only includes visible content unless `traverseHidden` is true.

#### Parameters

##### options

Serialization options

###### traverseHidden?

`boolean` = `true`

#### Returns

`Promise`\<`string`\>

XML string

***

### traverse()

> **traverse**(`callback`, `options`): `this`

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:268](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L268)

Depth-first traversal of the library tree.

#### Parameters

##### callback

[`TraverseCallback`](../type-aliases/TraverseCallback.md)

Function called for each visited node

##### options

[`TraverseOptions`](../interfaces/TraverseOptions.md) = `{}`

Traversal options

#### Returns

`this`

this (for chaining)

***

### parse()

> `static` **parse**(`libraryXML`, `options`): `Promise`\<`Library`\>

Defined in: [packages/b2c-tooling-sdk/src/operations/content/library.ts:192](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/library.ts#L192)

Parse library XML into a Library tree.

#### Parameters

##### libraryXML

`string`

Raw XML string of a content library

##### options

[`LibraryParseOptions`](../interfaces/LibraryParseOptions.md) = `{}`

Parse options

#### Returns

`Promise`\<`Library`\>

Parsed Library instance
