百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

haf

> 开发工具
开源

为您的 NodeJS 项目提供一个完全类型化、跨平台、持久的配置解决方案,具有出色的开发者体验!

190 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

为您的 NodeJS 项目提供一个完全类型化、跨平台、持久的配置解决方案,具有出色的开发者体验!

Haf ✏️

Haf is a fully typed , cross-platform, persistent JSON storage ⚙️ solution for your NodeJS projects with a great developer experience!

  • ✏️ Auto-completed dot-notation suggestions as you type when you try to get()/set()/delete()/reset() data from the store.
  • ✅ The type of the value you get() from the store is correctly inferred. So you always know what you'll get().
  • ❌ Non-nullable values aren't suggested on delete(). Trying to delete() a non-nullable field will throw a type error.

Go to gifs section to see it in action!

Installation

bash
npm i @batuhanw/haf

OR

yarn add @batuhanw/haf

Getting Started

1. Define Your Schema

typescript
interface DogSchema {
  name: string;
  age: number;
  toys: string[];
  vaccines: { name: string; date: string; nextDate?: string }[];
  appearance: {
    eyeColor: string;
    hairColor: {
      primary: string;
      secondary?: string;
      otherColors: string[];
    };
  };
  sterilizedAt?: string;
  hasPuppies: boolean;
}

2. Initiate Haf

typescript
import Haf from '@batuhanw/haf';

const haf = new Haf({
  name: 'myDog',
  defaultSchema: {
    name: 'Pop',
    age: 2,
    toys: ['socks', 'toilet paper'],
    vaccines: [
      { name: 'rabbies', date: '2020-01-01' },
      { name: 'parasite', date: '2020-01-01', nextDate: '2020-01-03' },
    ],
    appearance: {
      eyeColor: 'brown',
      hairColor: {
        primary: 'white',
        secondary: undefined,
        otherColors: ['black'],
      },
    },
    sterilizedAt: undefined,
    hasPuppies: false,
  },
});

3. Enjoy

Get

typescript
  const name = haf.get('name') // string
  const age = haf.get('age') // number
  const hasPuppies = haf.get('hasPuppies') // boolean
  const vaccines = haf.get('vaccines') // { name: string; date: string; nextDate?: string }[]
  const hairColor: haf.get('appearance.haircolor') // { primary: string; secondary?: string, otherColors: string[] }
  const secondaryHairColor: haf.get('appearance.hairColor.secondary') // string | undefined

  const invalid = haf.get('non-existent') // type error

Set

typescript
haf.set('name', 'Pop');
haf.set('appearance.hairColor', { primary: 'white' });
haf.set('appearance.hairColor.secondary', 'brown');
haf.set('appearance.hairColor.secondary', undefined);
haf.set('appearance.hairColor.otherColors', ['black']); // This will overwrite existing array

haf.set('name', 1); // type error
haf.set('toys', [1, 2]); // type error
haf.set('appearance.haircolor', { primary: 1 }); //type error
haf.set('appearance.hairColor.primary', 1); // type error
haf.set('appearance.haircolor', { notExist: 'white' }); //type error

Append

Appends given values to the existing array

typescript
haf.get('toys'); // ['socks', 'toilet paper']

haf.append('toys', 'human hand', 'bone');

haf.get('toys'); // ['socks', 'toilet paper', 'human hand', 'bone']

Delete

typescript
haf.delete('sterilizedAt');
haf.delete('appearance.hairColor.secondary');

haf.delete('name'); // type error
haf.delete('appearance.hairColor.primary'); // type error

Gifs

Get

Set

Delete

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptappcliconfignode

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具