npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@marcura/dadesk-ui-common

v2.0.3

Published

Basic set of most common tools used inside DA-Desk projects.

Downloads

25

Readme

@marcura/dadesk-ui-common

Basic set of most common tools used inside DA-Desk projects.

This version is expected to work with Angular 15.x.

@Models

Common

Debouncer
import {Debouncer} from '@marcura/dadesk-ui-common';

const debouncer = new Debouncer(window, 500);
debouncer.debounce('key', () => console.log('debounced operation'));
Destroyables

Registry of objects implementing IDestroyable interface, which should all be destroyed when registry does.

import {Destroyables} from '@marcura/dadesk-ui-common';

const destroyables = new Destroyables();
destroyables.add(new SomeDestroyable());
destroyables.add(new AnotherDestroyable());
destroyables.destroy();
Forms

Typed versions of Ng controls.

LazyProperty

Lazy loading utility for things we don't want to spawn before anybody really accesses.

import {LazyProperty} from '@marcura/dadesk-ui-common';

class Test {
  private readonly _sample: LazyProperty<number> = new LazyProperty(() => 123);
  public get sample(): number {
    return this._sample.value;
  }
}
ObservableSet

RX version of normal Set

import {ObservableSet} from '@marcura/dadesk-ui-common';

const observableSet = new ObservableSet<number>();
observableSet.changes$.subscribe(() => console.log('Set changed'));
observableSet.add(1); // Console: 'Set changed'
observableSet.delete(1); // Console: 'Set changed'
Observer

Observing utility, with few handy methods for listening on Observables. Extends Destroyables.

import {Observer} from '@marcura/dadesk-ui-common';

const observer = new Observer();
observer.listen(someObservable, (value) => console.log(value));
observer.bind(anotherObservable, someSubject);
observer.bindControl(yetAnotherObservable, someFormControl);
observer.destroy();
Popup
import {Popup} from '@marcura/dadesk-ui-common';

const popup = new Popup();
popup.opened$.subscribe(() => console.log('Popup opened'));
popup.closed$.subscribe(() => console.log('Popup closed'));
popup.open();
QueryParams, QueryParamsBuilder
import {QueryParams, QueryParamsBuilder} from '@marcura/dadesk-ui-common';

const builder: QueryParamsBuilder = new QueryParamsBuilder();
builder.add('param1', 'value1').add('param2', [1, 2, 3]);
const queryParams: QueryParams = builder.build();
Range
import {Range} from '@marcura/dadesk-ui-common';

const values: Range<number> = {from: 0, to: 100};
RemoteSubject

A class that provides a subject that loads its value asynchronously. The value is loaded only once and is shared among all subscribers.

import {RemoteSubject} from '@marcura/dadesk-ui-common';

const subject: RemoteSubject<string> = new RemoteSubject(() => of('Hello, world!'));
subject.subscribe((value) => console.log(value));
Request

Represents a request with a payload, result, and error type.

import {Request} from '@marcura/dadesk-ui-common';

const request: Request<string, number, Error> = new Request<string, number, Error>(
  'payload',
  (result) => console.log(result),
  (error) => console.error(error)
);
Rx

A utility class providing various RxJS operators and helper functions.

Snapshot

Represents a snapshot of an observable value that can be subscribed to, but also allows sync access to recent value via .get() method.

import {Snapshot} from '@marcura/dadesk-ui-common';

const source: BehaviorSubject<number> = new BehaviorSubject<number>(0);
const snapshot$: Snapshot<number> = new Snapshot(source);
snapshot$.subscribe((value) => console.log(value));
source.next(1);
console.log(snapshot$.get()); // 1
Sort

Sorting utilities.

State

Represents an observable state with sync get()/set() methods.

import {State} from '@marcura/dadesk-ui-common';

const state$: State<number> = new State<number>(0);
state$.subscribe((value) => console.log(value));
state$.set(1);
console.log(state$.get()); // 1
Worker

Worker that handles only one task at the same time. If new task is assigned via .handle(), the previous one is cancelled.

import {worker} from '@marcura/dadesk-ui-common';

const worker = new Worker();
worker.handle(
  someObservableTask(),
  (result) => console.log(result),
  (error) => console.error(error)
);

Testing

DevDebug

A collection of debugging utilities for development purposes.

import {DevDebug} from '@marcura/dadesk-ui-common';

const form = new FormGroup({
  name: new FormControl('', Validators.required),
  email: new FormControl('', Validators.email),
});
console.log(DevDebug.getFormErrors(form));
DevFormTesting

A collection of form testing utilities for unit tests.

import {DevFormTesting} from '@marcura/dadesk-ui-common';

const form = new FormGroup({
  name: new FormControl('', Validators.required),
  email: new FormControl('', Validators.email),
});

const error = DevFormTesting.allChildControls(form, (control) => control.valid);
expect(error).toBeNull();
DevTesting

Namespace containing utilities for development testing.

import {DevTesting} from '@marcura/dadesk-ui-common';

class SomeType {
  someProp: string = '';
}
const prop: DevTesting.PropNameValidator<SomeType> = DevTesting.createPropNameValidator<SomeType>();

desribe(SomeType.name, () => {
  describe(prop('someProp'), () => {
    // is fine
  });
  describe(prop('notExistingProp'), () => {
    // shows an error
  });
});

@Types:

Nullable
CompareFn
IsEqualFn
SearchFn
ResolveObservableFn
TypeOfControl
TypeOfObservable

@Functions

currentValue()
firstValueFrom()
nonNullControl()
warmUp()
valueEquals()

@Pipes

empty
isArray
isArrayNotEmpty
isDefined
isNumber
isObject
isObjectNotEmpty
isString
isStringNotEmpty
join
split

@Services

DebouncerService