@abcnews/alternating-case-to-object

中文文档
3.2.0发布于 2025/05/05ISCTypeScriptES Module近 30 天下载 7031

Convert an alternating case string to a JSON object

原始使用文档
文档目录5 节
  1. Usage
  2. Convert an object to a string
  3. Options
  4. Parse a string to an object
  5. Options

Alternating Case to Object

A function to convert alternating case ("ALTERNATINGcase") strings to objects ({alternating: 'case'}) and vice versa.

The ACTO string format supports numbers, bools, nulls, and lowercase strings (a-z0-9), as standalone values or as arrays.

This library provides a parse and stringify method to convert objects from and to strings respectively.

Usage

  1. Install with npm i @abcnews/alternating-case-to-object
  2. Import the library with import {parse, stringify} from '@abcnews/alternating-case-to-object'

Convert an object to a string

stringify({
  prop: 'value',
  second: 'thing',
  allowed: true,
  things: [100, 101],
});

// "PROPvalueSECONDthingALLOWEDyesTHINGS100THINGS101"

Options

propMap:Object

Props in the config will be renamed if they occur in this object. Note the propMap is the same format as you pass to parse(), so the map is applied in the opposite direction.

stringify(
  {
    'kebab-case': 'value',
  },
  {
    propMap: {
      kebabcase: 'kebab-case',
    },
  }
);

// "KEBABCASEvalue"

Parse a string to an object


parse('PROPvalueSECONDthingALLOWEDyesTHINGS100');

// >>>

{
  prop: 'value',
  second: 'thing',
  allowed: true,
  things: 100
}

Automatic type inference

  • Number values will be parsed as floats.
  • The values "true", "yes", "false" & "no" will be converted to the booleans true, true, false & false, respectively.
  • If a prop appears more than once, multiple values will be returned as an array:
parse('GROUPfirstGROUPsecondGROUPthird');

// >>>

{
  group: ['first', 'second', 'third'];
}

Every value in a prop which appears multiple times must be of the same type or an exception will be thrown. For example, this will throw:

parse('AtrueAstr');

Options

arrayProps:Array

Props in this array will always be returned as arrays, even if they occur in the config string zero or one time.

parse('AtrueAfalseBvalueAtrueDvalue', {
  arrayProps: ['a', 'b', 'c']
});

// >>>

{
  a: [true, false, true],
  b: ['value'],
  c: [],
  d: 'value'
}

propMap:Object

Props in the config will be renamed if they occur in this object.

parse('CAMELCASEtrueKEBABCASE100', {
  propMap: {
    camelcase: 'camelCase',
    kebabcase: 'kebab-case'
  }
});

// >>>

{
  camelCase: true,
  'kebab-case': 100
}

版本与发布记录

@abcnews/alternating-case-to-object 共发布 8 个版本,首次发布于 2018/02/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.2.0latest2025/05/051.5 年前
3.1.12023/07/173 年前
3.1.02022/11/243 年前
3.0.22021/05/035 年前
3.0.12021/02/235 年前
3.0.02021/02/235 年前

关于 @abcnews/alternating-case-to-object 的常见问题

@abcnews/alternating-case-to-object 是什么?

Convert an alternating case string to a JSON object

如何安装 @abcnews/alternating-case-to-object?

在项目目录运行 npm install @abcnews/alternating-case-to-object,或使用 pnpm add / yarn add / bun add。

@abcnews/alternating-case-to-object 支持 TypeScript 吗?

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

@abcnews/alternating-case-to-object 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@abcnews/alternating-case-to-object 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@abcnews/alternating-case-to-object 可以商用吗?

@abcnews/alternating-case-to-object 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@abcnews/alternating-case-to-object 的下载量有多少?

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

@abcnews/alternating-case-to-object 还在维护吗?

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