New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

tson-patch

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tson-patch

Statically typed JSON Patch

latest
Source
npmnpm
Version
1.1.7
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

TSON Patch

Statically typed JSON Patch operations

Usage

You have some kind of nested data that you want to work with. It could look something like this:

export type User = {
	id: string;
	name: {
		first: string;
		last?: string;
	}
	friends: {
		[from: string]: Array<{ name: string }>
	}
};

A mess to work with, right? Not anymore:

Basic operations

All operations are pure and return shallow copies

Get

import * as tp from 'tson-patch'
tp.get(user, ['friends', 'college', 0, 'name']) // Compiles just fine
tp.get(user, ['friends', 'college', 0, 'age']) // COMPILE ERROR: 'age' doesn't exist in 'name'

Set

tp.set(user, ['friends', 'college', 0, 'name'], 'John') // Now `user.friends.chess[0].name === 'John'`
tp.set(user, ['friends', 'college', 0], {name: 'John'}) // Exactly the same
tp.set(user, ['friends', 'college', 0, 'name'], {name: 'Oops'}) // COMPILE ERROR (types don't match)

Remove

tp.remove(user, ['id']) // COMPILE ERROR ('id' is not nullable)
tp.remove(user, ['name', 'last']) // '<User but without last name>'

Move

tp.move(user, ['id'], ['friends', 'college']) // COMPILE ERROR (Types don't match)
tp.move(user, ['id'], ['friends', 'college', 0, 'name']) // OK

Swap

tp.swap(user, ['id'], ['friends', 'chess']) // COMPILE ERROR (Types don't match)
tp.swap(user, ['id'], ['friends', 'chess', 0, 'name']) // OK

FAQs

Package last updated on 08 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts