@just-web-tech/get-set
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@just-web-tech/get-set

Type safe get and set properties using dot notation

npm version npm downloads npm license npm stars

Features

  • 🔑 Type safe
  • ⚡️ No dependencies
  • 📦 Tree shakeable
  • 🔥 < 1 kb size (gzip)

Install

npm i @just-web-tech/get-set

Usage

Safely getting and setting properties via dot notation

const project: Project = {
  name: '@just-web-tech/get-set',
  created: new Date(),
  test: {
    framework: 'vitest',
  },
  files: [{ folder: 'dist' }]
};

const file = getValue(project, 'files.0.folder'); // 'dist'
setValue(project, 'files.0.folder', 'build'); // project.files is equal to ['build']

Utility types

Path<T>

Returns a string representation of the paths for all properties

type Paths = Path<Project>;
// "name" | "created" | "test" | "files"
// "test.framework" | `files.${number}` | `files.${number}.folder`

PathValue<T, P>

Returns the type of the property at the specified path

type Created = PathValue<Project, 'created'>; // Date

Package Sidebar

Install

npm i @just-web-tech/get-set

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

9.05 kB

Total Files

14

Last publish

Collaborators

  • just-web-tech