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

@rustable/utils

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rustable/utils

Utility TypeScript utilities inspired by Rust, providing type-safe implementations of HashMap, TypeId, deep cloning, hashing, and equality comparison

  • 0.1.2
  • Source
  • npm
  • Socket score

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

@rustable/utils

This is the utilities package of the Rustable project, providing fundamental utilities and type management functionalities. The package implements essential features like type identification, object cloning, hashing, and string manipulation.

Installation

npm install @rustable/utils
# or
yarn add @rustable/utils
# or
pnpm add @rustable/utils

Key Components

Type Identification System (type_id.ts)

  • Provides a robust type identification system
  • Uses WeakMap for efficient memory management
  • Supports generic type parameters
  • Ensures type safety using TypeScript's branded type pattern

String Manipulation (stringify.ts)

  • Advanced string manipulation and conversion utilities
  • Handles complex object to string conversions

Hashing (hash.ts)

  • Implements hashing functionality for various data types
  • Provides consistent hash generation

Object Cloning (clone.ts)

  • Deep cloning utilities for objects
  • Handles complex data structures

Equality Comparison (eq.ts)

  • Implements equality comparison functionality
  • Supports deep equality checks

Usage

Import the required utilities from the package:

import { typeId, clone, hash, stringify } from '@rustable/utils';

Example: Using Type ID

class MyClass {}
const id = typeId(MyClass); // Get type ID for class

// With generic parameters
class Container<T> {}
const stringContainerId = typeId(Container, [String]);

Example: Deep Cloning

import { deepCopy } from '@rustable/utils';

// Cloning simple objects
const original = { name: 'John', age: 30 };
const clone = deepCopy(original);

// Cloning complex objects with circular references
const complexObj = {
  data: [1, 2, 3],
  date: new Date(),
};
complexObj.self = complexObj; // circular reference
const cloned = deepCopy(complexObj);

Example: Hashing

import { hash } from '@rustable/utils';

// Hash simple values
const numberHash = hash(42);
const stringHash = hash('Hello World');

// Hash objects
const objectHash = hash({ x: 1, y: 2 });
const arrayHash = hash([1, 2, 3]);

Example: Equality Comparison

import { equals } from '@rustable/utils';

// Compare simple values
console.log(equals(5, 5)); // true
console.log(equals('hello', 'hello')); // true

// Compare objects
const obj1 = { x: 1, y: [1, 2, 3] };
const obj2 = { x: 1, y: [1, 2, 3] };
console.log(equals(obj1, obj2)); // true

Notes

  • All utilities are designed with TypeScript's type system in mind
  • The package uses WeakMap for efficient memory management
  • Generic type support is available where applicable

License

MIT © illuxiza

Keywords

FAQs

Package last updated on 12 Dec 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

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