voipke-splitter
v1.0.2
Published
Split string by fixed length
Downloads
293
Readme
voipke-splitter
将字符串按固定长度分割的工具,支持 CLI 和库两种使用方式。
安装
npm install voipke-splitter使用方式
1. 作为库在项目中使用
// 方式1: 命名导入
import { splitByLength } from 'voipke-splitter';
const result = splitByLength('abcdefgh', 3);
console.log(result); // ['abc', 'def', 'gh']
// 方式2: 默认导入
import splitByLength from 'voipke-splitter';
const result = splitByLength('hello', 2);
console.log(result); // ['he', 'll', 'o']2. 作为 CLI 工具使用
全局安装:
npm install -g voipke-splitter
voipke-splitter abcdef 3或使用 npx:
npx voipke-splitter abcdef 3开发
安装依赖
npm install编译打包
npm run build编译产物输出到 dist/ 目录。
运行
npm startVSCode 调试
- 按
F5或点击左侧调试图标,选择"调试"配置 - 程序会在集成终端中运行,按照提示输入字符串和分割长度
- 可以在代码中设置断点进行调试
API
splitByLength(str: string, length: number): string[]
按固定长度分割字符串。
str: 要分割的字符串length: 每段的长度(必须是正整数)- 返回: 分割后的字符串数组
License
MIT
