@apple/cktool.core

中文文档
1.3.2发布于 2022/06/04SEE LICENSE IN LICENSE.mdTypeScriptESM + CJS近 30 天下载 2540

Apple CKTool JS client library runtime support

原始使用文档
文档目录5 节
  1. Getting Started
  2. Strict Numeric Types
  3. Casting Functions
  4. Int64, Float, and Double Support
  5. UUIDs

CKTool JS Core Package

This package is part of the CKTool JS JavaScript client library suite and is used to support other CKTool JS packages.

Don't use this package on its own. It is automatically pulled in when you include @apple/cktool.database in your package.json dependencies.

Getting Started

See Apple Developer Documentation for more details on how to get started using CKTool JS.

Strict Numeric Types

There are several branded types used to mark validated values. For example, the Int32 type is a branded numeric type that is assignaable to number but number is not directly assignable to it.

const a: number = toInt32(12); // OK
const b: Int32 = 12; // Error

Casting Functions

This client library attempts to be as type-safe as possible. There are several data types that must be validated in order to be passed to an operation. For example, where an Int32 would be expected, you must first pass your constant through the toInt32 cast function. The Int32 cast function does the following:

  • Validates that the value is a numeric type.
  • Validates that the number is an integer in Int32 range.
  • Returns an Int32 value that will pass type checking.

Do NOT use type assertions to cast a related type, such as number to a branded type. Such an approach is not guaranteed to compile in future and an invalid value may be type asserted, which can lead to errors down the line.

Int64, Float, and Double Support

Support for Int64, Float, and Double is achieved with the bignumber.js library. Whenever one of those numeric types are returned from an operation, it will be a BigNumber instance. In order to perform operations on those instances, such as addition or subtraction, you'll need to use the BigNumber methods. See the documentation for BigNumber at https://github.com/MikeMcl/bignumber.js.

The toInt64 cast function will do the following:

  • Validates that the value is a numeric type.
  • Validates that the number is an integer in Int64 range.
  • Returns a BigNumber instance of type Int64.

The toFloat cast function will do the following:

  • Validates that the value is a numeric type.
  • Validates that the number is an integer in Float range.
  • Returns a BigNumber instance of type Float.

The toDouble cast function will do the following:

  • Validates that the value is a numeric type.
  • Validates that the number is an integer in Double range.
  • Returns a BigNumber instance of type Double.

UUIDs

To pass a Uuid to a function, use the toUuid cast function. To create a Uuid object, use the createUuid function.

版本与发布记录

@apple/cktool.core 共发布 8 个版本,首次发布于 2021/12/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.3.2latest2022/06/044 年前
1.2.3412022/04/264 年前
1.2.282021/12/034 年前
1.2.152021/12/014 年前
1.2.132021/12/014 年前
1.2.72021/12/014 年前

关于 @apple/cktool.core 的常见问题

@apple/cktool.core 是什么?

Apple CKTool JS client library runtime support

如何安装 @apple/cktool.core?

在项目目录运行 npm install @apple/cktool.core,或使用 pnpm add / yarn add / bun add。

@apple/cktool.core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@apple/cktool.core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@apple/cktool.core 可以商用吗?

@apple/cktool.core 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@apple/cktool.core 的下载量有多少?

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

@apple/cktool.core 还在维护吗?

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