New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bearclaw/immutable-class

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bearclaw/immutable-class

This library provides helper functions to extend `class-transformer` functionality to create immutable classes. It also provides helper functions to work with immutable classes using `immer`.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

immutable-class

This library provides helper functions to extend class-transformer functionality to create immutable classes. It also provides helper functions to work with immutable classes using immer.

instanceToImmutableInstance

Converts a class (constructor) object to a new immutable class (constructor) object. Also works with arrays.

class MyClass {
  foo!: string
}
const existing = new MyClass();
existing.foo = 'bar'; // No errors
const instance = instanceToImmutableInstance(existing);
instance.foo = 'foo'; // throws a read only property error

instanceToImmutablePlain

Converts a class (constructor) object to an immutable plain (literal) object. Also works with arrays.

class MyClass {
  foo!: string
}
const instance = new MyClass();
instance.foo = 'bar'; // No errors
const plain = instanceToImmutablePlain(instance);
plain.foo = 'foo'; // throws a read only property error

patchImmutableInstance

Produce the next immutable class (constructor) object by patching the existing class (constructor) object. Also works with arrays.

class MyClass {
  foo!: string
}
const instance = new MyClass();
instance.foo = 'bar'; // No errors
const updated = patchImmutableInstance(instance, { foo: 'some value' });
instance.foo = 'foo'; // throws a read only property error

plainToImmutableInstance

Converts a plain (literal) object to an immutable class (constructor) object. Also works with arrays.

class MyClass {
  foo!: string
}
const plain = { foo: 'example' };
plain.foo = 'bar'; // No errors
const instance = plainToImmutableInstance(MyClass, plain);
instance.foo = 'foo'; // throws a read only property error

produceImmutableInstance

Produce the next immutable class (constructor) object by modifying the current class (constructor) object with a recipe function. Also works with arrays.

class MyClass {
  foo!: string
}
const instance = new MyClass();
instance.foo = 'bar'; // No errors
const updated = produceImmutableInstance(instance, draft => {
  draft.foo = 'some value'
});
instance.foo = 'foo'; // throws a read only property error

Contributing

Running unit tests

Run nx test immutable-class to execute the unit tests via Jest.- immutable-class

FAQs

Package last updated on 19 Oct 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc