lz-draft-compress

Compress draft text with lz-string before writing to localStorage to save storage space and reduce quota pressure. Suitable for browser-side scenarios that need to compress and store user drafts.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "lz-draft-compress" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-86962e7524f55ecdbd0484da4b32df1cfb1f8bc46f5bb04c50b1b56f3759d29f. Verify the upstream source and version against https://skillhub.cn/skills/user_f1b049da/prq20263590 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Compress draft text with lz-string before writing to localStorage to save storage space and reduce quota pressure. Suitable for browser-side scenarios that need to compress and store user drafts.

0 Downloads

Introduction source: third_party · user_f1b049da · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: lz-draft-compress
slug: prq20263590
displayName: 草稿压缩存储
version: 1.0.0
summary: 用 lz-string 压缩本地草稿,节省 localStorage 空间。
license: MIT
description: 用 lz-string 压缩客户草稿后再写入 localStorage,节省空间并减少配额压力。当用户需要草稿压缩、lz-string、localStorage 省空间、压缩存草稿时使用。

草稿压缩存储(lz-string)

灵感:能力工具箱 lz-compress(pkg: lz-string)。

把客户草稿 JSON 用 lz-string 压缩成字符串再存 localStorage,缓解配额与大笔记占空间问题。

何时使用

  • 跟进笔记长、草稿对象大
  • localStorage 接近配额或频繁 QuotaExceeded
  • 只需本地草稿,不必上 IndexedDB 的轻量方案

硬约束

  1. 依赖 lz-string;推荐 compressToUTF16 / decompressFromUTF16(较适合 localStorage)。
  2. 读写成对封装;解压失败返回中文原因并允许清空坏数据。
  3. Key 带版本前缀(如 crm:draft:v1:),便于将来迁移。
  4. 先 JSON.stringify 再压缩;读出先解压再 JSON.parse。
  5. 不把压缩串当加密——仅省空间,敏感数据另议。

推荐实现要点

import LZString from 'lz-string'

const PREFIX = 'crm:draft:v1:'

export function saveDraftCompressed(id: string, data: unknown): { ok: true } | { ok: false; reason: string } {
  try {
    const raw = JSON.stringify(data)
    const packed = LZString.compressToUTF16(raw)
    if (!packed) return { ok: false, reason: '压缩失败' }
    localStorage.setItem(PREFIX + id, packed)
    return { ok: true }
  } catch {
    return { ok: false, reason: '存储失败(可能超出配额)' }
  }
}

export function loadDraftCompressed<T = unknown>(id: string): { ok: true; data: T } | { ok: false; reason: string } {
  const packed = localStorage.getItem(PREFIX + id)
  if (!packed) return { ok: false, reason: '无草稿' }
  try {
    const raw = LZString.decompressFromUTF16(packed)
    if (!raw) return { ok: false, reason: '解压失败' }
    return { ok: true, data: JSON.parse(raw) as T }
  } catch {
    return { ok: false, reason: '草稿损坏' }
  }
}

export function removeDraftCompressed(id: string) {
  localStorage.removeItem(PREFIX + id)
}

Agent 步骤

  1. 安装 lz-string,封装 save/load/remove。
  2. 与 Immer 草稿更新衔接:produce 后 saveDraftCompressed。
  3. 自测:大文本存取往返一致;可对比压缩前后 length。

附加

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value75/100

Highlights

  • 解决前端开发中 localStorage 存储大文本的配额问题
  • 提供轻量级本地草稿压缩方案,实用性强
Trigger Precision85/100

Highlights

  • 触发词覆盖合理,明确描述适用场景
Structure and Standards88/100

Highlights

  • 文档结构清晰,包含完整的使用说明和实现要点
  • frontmatter 完整,代码示例规范
Execution Reliability90/100

Areas to improve

  • 引用文件缺失 Reported severity: Minor

    SKILL.md 中引用了 [README.md]、[reference.md]、[templates/usage.md] 等文件,但未在传入内容中提供

    Recommendation: 建议补充相关引用文件,或移除无法提供的引用链接

Highlights

  • 提供了完整的 TypeScript 实现代码
  • 错误处理完善,返回值设计合理
  • 工具来源明确,参数使用正确
Evidence Verifiability (mean of the first four)85/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.