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

clever-ts-utilities

v2.4.2

Published

This library is a set of typescript utilities to save time

Downloads

134

Readme

clever-ts-utilities

This library is a set of typescript utilities to save time

Install

run npm install clever-ts-utilities. And then, use functions like this: let clone = copy(data);

Arrays

paginate

returns an items paginated array from an array, index page and size page

paginate(params: {data: Array<any>, indexPage: number, pageSize: number}): Array<any>

strRemoveBeginingCommonChars

Remove begening common chars of two strings

strRemoveBeginingCommonChars(params: {[key: string]: string}): {[key: string]: string}

getDictionnaryValues

Get values from a dictionary

getValuesFromDictionnary(dic: {[key: string]: any}): any[]

isAllEqual

Checks that all string values in an array are equal

isAllEqual(chars: any[]): boolean

enumarableFromListEqual

Return a sublist from a list that has column that contain a certain value.

enumarableFromListEqual(list: any[], column: string, value: any): any[]

deleteFromArray

Delete items from an array.

deleteFromArray(array: any[], item: any): any[] | boolean

objectSort

Sort array by property.

objectSort(arr: Array<any>, prop: string, isAscendent: boolean = true): Array<any>

Common

copy

By default javacript when assigning one variable to another, refers to the same memory address. This method allows you to copy the passed element whatever its type.

copy(obj: any): any

isUndefinedOrNull

deternine if data is undefined or null.

isUndefinedOrNull(data: string): boolean

jsType

Used to literally determine the type of the passed object (including the array type)

jsType(obj: any): string

getObjectByFieldValue

Get an object in a list by value of one field, like id.

getObjectByFieldValue(obj: any[], fieldname: string, fieldvalue: any): any

objectsEquals

Match two objects.

objectsEquals(obj1: any, obj2: any, ignoreProps?: string[]): boolean

allObjectsEquals

Match an object list.

allObjectsEquals(objs: any[], ignoreProps?: string[]): boolean

arrayObjectContain

Check if an array contain object

arrayObjectContain(array: any[], obj: any, ignoreProps?: string[]): boolean

setObjectsEquals

Execute a Set Javascript in scope of object

setObjectsEquals(objs: any[], ignoreProps?: string[]): any[]

Dates

dateOperation

Allows you to perform arithmetic operations on dates

dateOperation(params: {date: Date, amount: number, operation: DateOperationEnum}): Date

dateCompare

Allow you to quickly compare dates

dateCompare(first: Date, operator: DateCompareOperator, second: Date): boolean

dateMonthPeriod

Takes date and return first and last date of the current month

dateMonthPeriod(date: Date): Array<Date>

dateYearPeriod

Takes date and return first and last date of the current year

dateYearPeriod(date: Date): Array<Date>

Strings

cleanSpace

Erase spaces in a character chain

cleanSpace(str: string): string

thousandSeparator

Adds thousands separators in a string

thousandSeparator(nombre: string | number, args: ThousandSeparatorArg = {decimal: true, pres: 2, arround: false}): string

isStringUndefinedOrNull

deternine if a string is undefined or null or empty.

isStringUndefinedOrNullOrEmpty(data: string): boolean

getCharsAt

Reduce string dictionnary to chars at specified position

getCharsAt(paramList: {[key: string]: string}, ofs: number): {[key: string]: string}

insertString

Insert string into another by refering an anchor around it string can be added.

insertString(params: {
  str: string;
  toAdd: string;
  anchor: string;
  position: "before" | "after";
}): string

CharsCollection_&_CharsIteration

Manage iterations on chars in string

const charCollection = new CharsCollection("alphabet");
const charIteration = charCollection.createIterator();
while (charIteration.hasMore()) {
  console.log(charIteration.getNext());
}
console.log(charIteration.toList());

Trim_Object

Apply trim on all properties of an object

trimObject(obj: any): any;

------------------------------------
// Example:

const obj: any = {
    alpha: '   dfg  dfg     ',
    beta: '     ddgdg    ',
    qs: [
        {
            al: ' dfgdf ',
            df: 2,
            azq: false
        },
        {
            al: ' dfgdf ',
            df: 2,
            azq: false
        },
    ],
    az: {
        alpha2: '   dgfgd dfgdfg  ',
        beta2: {
            alpha3: '   dfgdfg   dfg',
            sd: 12,
            xd: true,
        }
    }
}

console.log(trimObject(obj));

// Output:
// {
//   "alpha": "dfg  dfg",
//   "beta": "ddgdg",
//   "qs": [
//     {
//       "al": "dfgdf",
//       "df": 2,
//       "azq": false
//     },
//     {
//       "al": "dfgdf",
//       "df": 2,
//       "azq": false
//     }
//   ],
//   "az": {
//     "alpha2": "dgfgd dfgdfg",
//     "beta2": {
//       "alpha3": "dfgdfg   dfg",
//       "sd": 12,
//       "xd": true
//     }
//   }
// }

Files

fileToBase64

Convert file to base 64

fileToBase64(file: File): Promise<string | any>

fileToBlob

Convert file to blob

fileToBlob(file: File): Promise<Blob | any>

fileToString

Convert file to string

fileToString(file: File): Promise<string | ArrayBuffer>

serializeFile

Convert File objet to FileModel

serializeFile(file: File): Promise<FileModel>

fileModelToBlob

Convert FileModel objet to Blob

fileModelToBlob(fileModel: FileModel): Blob

buildDownloadFileUrl

Return the download url of a file

buildDownloadFileUrl(file: FileModel): string

HttpRequestPendingFacade

Class that manage http request pendings

getInstance

Get instance of the class

incrementUrl

Increment the url collection

decrementUrl

Decrement the url collection

isPending

Check if request is pending. It must be used in Observer class.

addObserver

Register observer

removeObserver

Unregister observer

CleanArchitectureUtils

This is a set of utilities for clean architecture project.

BaseModelWithout-props

This class maybe extended by models and define an update method to model

export class User extends BaseModelWithoutProps<User> {
  login: string;
  email: string;
  password: string;
  phone: string;
  avatar: string;
}

// Initialize a new instance of the User class:
const user: User = new User(); // option 1

const user: User = new User({  // option 2
  login: 'admin',
  email: '[email protected]',
});

// Update the user instance:
user.update({
  login: 'admin 2',
});

BaseModel

This class work like BaseModelWithoutProps. But add id, createdAt and updatedAt properties to model

ICommandHandler

This is a command handler interface for CQRS approach

interface ICommandHandler<C>

IQueryHandler

This is a query handler interface for CQRS approach

interface IQueryHandler<Q, R>

IUsecase

This is a usecase interface for hexagonal and approach

interface IUsecase<C, T>

IMapper

This is a mapper interface for mapping between domain and data layer

interface IMapper<I, O>

AutoMapper

AutoMapper allow to map automaticaly Objects like C# or Java AutoMappers.

It work well with EsNext target configuration

const source = {
  name: "John",
  surname: "Doe",
  age: 30
}

interface IDestination {
  firstName: string;
  lastName: string;
  age: number;
}

const destination = new AutoMapper()
  .forSource(Object)
  .forDestination(IDestination)
  .mapFrom("name", "firstName") // Optional  - if not specified, it will be mapped by default
  .mapFrom("surname", "lastName") // Optional  - if not specified, it will be mapped by default
  .execute(source);

Types

OmitMethods

OmitMethods type omit methods from type.

type OmitMethods<T>

Responsive Dialog width

Get responsive dialog width with 90% width for mobile devices

export function responsiveDialogWidth(width: string): string