@univerjs/core
本 API 页面目前提供英文正文。代码签名与标识符不随界面语言变化。
Core runtime, data models, command system, dependency injection, and Facade APIs for Univer.
TypeScript
import { Univer } from '@univerjs/core'const univer = new Univer(IUniverConfig)Entry Points
- Facade:
@univerjs/core/facade
Additional APIs include:
getDrawingOrderIndex()andnormalizeDrawingOrderIndex()for stable, absolute drawing-layer positions.setWith()for Lodash-compatible deep assignment with custom container creation.DocumentDataModel.getStatistics(options?)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.
TypeScript
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. |
TypeScript
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
TypeScript
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}你觉得这篇文档如何?