@dojo/core

中文文档
2.0.0发布于 2018/05/02BSD-3-ClauseCommonJS近 30 天下载 1959

Basic utilites for common TypeScript development

原始使用文档
文档目录11 节
  1. Usage
  2. Features
  3. Feature Detection
  4. Language Utilities
  5. load
  6. Promises and Asynchronous Operations
  7. How Do I Contribute?
  8. Code Style
  9. Installation
  10. Testing
  11. Licensing information

Dojo 2 core

Build Status codecov.io npm version FOSSA Status

This package provides a set of language helpers, utility functions, and classes for writing TypeScript applications. It includes APIs for feature detection, asynchronous operations, basic event handling, and making HTTP requests.

Usage

To use @dojo/core, install the package along with its required peer dependencies:

npm install @dojo/core

# peer dependencies
npm install @dojo/has
npm install @dojo/shim

Features

Feature Detection

Using the latest Web technologies isn't always as straightforward as developers would like due to differing support across platforms. @dojo/core/has provides a simple feature detection API that makes it easy to detect which platforms support which features.

Language Utilities

The core package provides modules offering language utilities. Some of these are heavily based on methods in the ES2015 proposal; others are additional APIs for commonly-performed tasks.

array

The @dojo/core/array module contains analogs to some of the ES2015 Array APIs.

lang

The @dojo/core/lang module contains various utility functions for tasks such as copying objects and creating late-bound or partially applied functions.

load

The @dojo/core/load module can be used to dynamically load modules or other arbitrary resources via plugins.

math

The @dojo/core/math module contains analogs to a number of ES2015 APIs, including many trigonometric and logarithmic functions.

string

The @dojo/core/stringExtras module contains various string functions that are not available as part of the ES2015 String APIs.

UrlSearchParams

The @dojo/core/UrlSearchParams class can be used to parse and generate URL query strings.

Event handling

The @dojo/core/on module contains methods to handle events across types of listeners. It also includes methods to handle different event use cases including only firing once and pauseable events.

HTTP requests

The @dojo/core/request module contains methods to simplify making HTTP requests. It can handle making requests in both node and the browser through the same methods.

Promises and Asynchronous Operations

Promise

The @dojo/core/Promise class is an implementation of the ES2015 Promise API that also includes static state inspection and a finally method for cleanup actions.

@dojo/core/async contains a number of classes and utility modules to simplify working with asynchronous operations.

Task

The @dojo/core/async/Task class is an extension of @dojo/core/Promise that provides cancelation support.

How Do I Contribute?

We appreciate your interest! Please see the Dojo 2 Meta Repository for the Contributing Guidelines.

Code Style

This repository uses prettier for code styling rules and formatting. A pre-commit hook is installed automatically and configured to run prettier against all staged files as per the configuration in the project's package.json.

An additional npm script to run prettier (with write set to true) against all src and test project files is available by running:

npm run prettier

Installation

To start working with this package, clone the repository and run npm install.

In order to build the project run grunt dev or grunt dist.

Testing

Test cases MUST be written using Intern using the Object test interface and Assert assertion interface.

90% branch coverage MUST be provided for all code submitted to this repository, as reported by istanbul’s combined coverage results for all supported platforms.

To test locally in node run:

grunt test

To test against browsers with a local selenium server run:

grunt test:local

To test against BrowserStack or Sauce Labs run:

grunt test:browserstack

or

grunt test:saucelabs

Licensing information

© 2004–2018 JS Foundation & contributors. New BSD license.

Some string functions (codePointAt, fromCodePoint, and repeat) adopted from polyfills by Mathias Bynens, under the MIT license.

See LICENSE for details.

FOSSA Status

版本与发布记录

@dojo/core 共发布 26 个版本,首次发布于 2017/01/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2018/05/028 年前
0.5.02018/03/228 年前
0.4.0rc12018/02/268 年前
0.3.1beta52018/01/128 年前
0.3.02017/12/018 年前
0.2.1beta42017/11/159 年前

其他发布通道:beta1 → 2.0.0-beta1.4,beta2 → 2.0.0-beta2.4,beta3 → 0.1.0,beta4 → 0.2.1,beta5 → 0.3.1,rc1 → 0.4.0。

关于 @dojo/core 的常见问题

@dojo/core 是什么?

Basic utilites for common TypeScript development

如何安装 @dojo/core?

在项目目录运行 npm install @dojo/core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@dojo/has(^2.0.0)、@dojo/shim(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dojo/core 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dojo__core 是否存在。

@dojo/core 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dojo/core 可以商用吗?

@dojo/core 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@dojo/core 的下载量有多少?

根据 npm 官方下载统计,@dojo/core 在 2026/10/13 – 2026/11/11 这 30 天内被下载 1,959 次,日均约 65 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dojo/core 还在维护吗?

最新版本 2.0.0 发布于 2018/05/02(8 年前);至今共发布 26 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/01/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。