Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@furystack/utils

Package Overview
Dependencies
Maintainers
0
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@furystack/utils

General utilities

  • 8.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-60.53%
Maintainers
0
Weekly downloads
 
Created
Source

@furystack/utils

General utilities, forked from @furystack/utils

Disposable

You can implement disposable resources and use them with a using() or usingAsync() syntax. Example:

class Resource implements IDisposable {
  dispose() {
    // cleanup logics
  }
}

using(new Resource(), (resource) => {
  // do something with the resource
})

usingAsync(new Resource(), async (resource) => {
  // do something with the resource, allows awaiting promises
})

ObservableValue and ValueObservers

You can track value changes using with this simple Observable implementation.

Example:

const observableValue = new ObservableValue<number>(0)
const observer = observableValue.subscribe((newValue) => {
  console.log('Value changed:', newValue)
})

// To update the value
observableValue.setValue(Math.random())
// if you want to dispose a single observer
observer[Symbol.dispose]()
// if you want to dispose the whole observableValue with all of its observers:
observableValue[Symbol.dispose]()

PathHelper

The class contains small helper methods for path transformation and manipulation.

Retrier

Retrier is a utility that can keep trying an operation until it succeeds, times out or reach a specified retry limit.

const funcToRetry: () => Promise<boolean> = async () => {
  const hasSucceeded = false
  // ...
  // custom logic
  // ...
  return hasSucceeded
}
const retrierSuccess = await Retrier.create(funcToRetry)
  .setup({
    Retries: 3,
    RetryIntervalMs: 1,
    timeoutMs: 1000,
  })
  .run()

Trace

Trace is an utility that can be used to track method calls, method returns and errors

const methodTracer: IDisposable = Trace.method({
  object: myObjectInstance, // You can define an object constructor for static methods as well
  method: myObjectInstance.method, // The method to be tracked
  isAsync: true, // if you set to async, method finished will be *await*-ed
  onCalled: (traceData) => {
    console.log('Method called:', traceData)
  },
  onFinished: (traceData) => {
    console.log('Method call finished:', traceData)
  },
  onError: (traceData) => {
    console.log('Method throwed an error:', traceData)
  },
})

// if you want to stop receiving events
methodTracer[Symbol.dispose]()

Keywords

FAQs

Package last updated on 07 Nov 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