jev-leftpad:用 LLM 调用替代 padStart() 的 npm 包

Hacker News 热门(buzzing.cc 中文翻译)·2026-09-21 20:14·49分钟前·fka
AI 导读

npm 包 jev-leftpad 把 JavaScript 的字符串补位交给大模型完成:调用 leftPad(value, targetLength) 时通过 TypeSafe 的 @typesafe-ai/sdk 请求 jev-latest,由模型在 space_0 到 space_10 中选一个选项,因此最多只能补 10 个空格。

Hacker News 热门(buzzing.cc 中文翻译)
33AI 编辑部评分,满分 100

jev-leftpad:用 LLM 调用替代 padStart() 的 npm 包

2026-09-21 20:14· 49分钟前· fka
AI 导读

npm 包 jev-leftpad 把 JavaScript 的字符串补位交给大模型完成:调用 leftPad(value, targetLength) 时通过 TypeSafe 的 @typesafe-ai/sdk 请求 jev-latest,由模型在 space_0 到 space_10 中选一个选项,因此最多只能补 10 个空格。

Could this be one line with padStart()? Yes. Does it need a model call? No. Anyway:

npm install jev-leftpad
import leftPad from 'jev-leftpad';

const result = await leftPad('jev', 8);

console.log(JSON.stringify(result));
// "     jev" (probably)

Set TYPESAFE_API_KEY before using it. jev-leftpad uses jev-latest through TypeSafe's native @typesafe-ai/sdk. It requires Node.js 20 or newer.

API

await leftPad(value, targetLength)

targetLength must be a non-negative safe integer.

Jev gets one Choice with criteria named space_0, space_1, space_2, and so on, written directly up to space_10. For the example above, it should choose space_5. JavaScript reads the number, creates five spaces, and puts the value after them.

This means the package can add between 0 and 10 spaces. If more than 10 spaces are needed, Jev has no correct option. Which feels appropriate for this project.

There is one TypeSafe API request per call and retries are disabled. The request can fail, Jev can choose the wrong option, and it costs more than padStart(). Please don't use this in production. Or anything important.

Development

npm install
npm test

The tests mock Jev. They don't need an API key and don't spend any TypeSafe credits.

来源:Hacker News 热门(buzzing.cc 中文翻译)· github.com