# @univerjs/core

- Human documentation: [https://docs.univer.ai/reference/packages/plugins/univerjs/core](https://docs.univer.ai/reference/packages/plugins/univerjs/core)

- Agent Markdown: [https://docs.univer.ai/reference/packages/plugins/univerjs/core.md](https://docs.univer.ai/reference/packages/plugins/univerjs/core.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [packages/plugins/univerjs/core.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/packages/plugins/univerjs/core.mdx)

---

Core runtime, data models, command system, dependency injection, and Facade APIs for Univer.

```typescript
// [!code word:Univer]
// [!code word:IUniverConfig]
import { Univer } from '@univerjs/core'

const univer = new Univer(IUniverConfig)
```

## Entry Points

* Facade: `@univerjs/core/facade`

Additional APIs include:

* `getDrawingOrderIndex()` and `normalizeDrawingOrderIndex()` for stable, absolute drawing-layer positions.
* `setWith()` for Lodash-compatible deep assignment with custom container creation.
* [`DocumentDataModel.getStatistics(options?)`](#document-statistics) for asynchronous, locale-aware document statistics.

## Deep assignment with `setWith`

`setWith(object, path, value, customizer)` is exported from `@univerjs/core`. It follows Lodash `setWith` semantics and is useful when an integration must control how missing path containers are created.

```ts
import { setWith } from '@univerjs/core'

const config = {}
setWith(config, ['sheets', 'sales', 'enabled'], true, Object)
```

## Document statistics

`DocumentDataModel.getStatistics()` calculates locale-aware word, character, and paragraph counts for a whole document or selected ranges.

```typescript
getStatistics(options?: IDocumentStatisticsOptions): Promise<IDocumentStatistics>
```

| Option   | Purpose                                                             |
| -------- | ------------------------------------------------------------------- |
| `locale` | Select the locale used by `Intl.Segmenter`.                         |
| `ranges` | Count only the supplied text ranges; overlapping ranges are merged. |
| `signal` | Cancel a calculation that is no longer needed.                      |

```ts
import { DocumentDataModel, LocaleType } from '@univerjs/core'

const model = new DocumentDataModel({ body: { dataStream: 'Hello world.\r\n' } })
const statistics = await model.getStatistics({ locale: LocaleType.EN_US })

console.log(statistics.words, statistics.charactersWithSpaces, statistics.paragraphs)
```

The result also includes `charactersWithoutSpaces`, `nonAsianWords`, and `asianCharactersAndKoreanWords`.

## IUniverConfig

```ts
import type { Theme } from '@univerjs/themes'
import type { Dependency, IDisposable } from './common/di'
import type { UnitModel } from './common/unit'
import type { LogLevel } from './services/log/log.service'
import type { DependencyOverride } from './services/plugin/plugin-override'
import type { Plugin, PluginCtor } from './services/plugin/plugin.service'
import type { ILocales } from './shared'
import type { LocaleType } from './types/enum/locale-type'

export interface IUniverConfig {
  /**
   * The theme of the Univer instance, default using the default theme.
   */
  theme?: Theme

  /**
   * Whether to use dark mode.
   * @default false
   */
  darkMode?: boolean

  /**
   * The locale of the Univer instance.
   */
  locale?: LocaleType

  /**
   * The region used for locale-dependent formatting.
   * It follows `locale` until explicitly configured.
   */
  region?: LocaleType

  /**
   * The direction of the Univer instance.
   * @default 'ltr'
   */
  direction?: 'ltr' | 'rtl'

  /**
   * The locales to be used
   */
  locales?: ILocales

  /**
   * The log level of the Univer instance.
   */
  logLevel?: LogLevel

  /**
   * Whether to enable logging for command execution.
   * @default false
   */
  logCommandExecution?: boolean

  /**
   * The override dependencies of the Univer instance.
   */
  override?: DependencyOverride
}
```
