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

backk-frontend-utils

v1.0.128

Published

Web frontend utils for Backk microservices

Downloads

142

Readme

Backk Frontend Utils

This contains utilities needed to run generated Backk frontend clients in your frontend client project.

Installation

npm install --save --save-exact backk-frontend-utils

Utility functions

getInputType

function getInputType<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
): string 

Gets the input type for property propertyName of class Class

Possible return values are:

  • text
  • email
  • password
  • search
  • tel
  • url
  • color
  • file
  • checkbox
  • number
  • month
  • date
  • time
  • datetime-local
  • select

getInstanceWithUndefinedRemovedFromArrays

function getInstanceWithUndefinedRemovedFromArrays(instance: any): any

creates and returns a new instance from instance where undefined values are removed from array type properties. The instance supplied in argument is not changed.

getSelectInputPossibleValues

function getSelectInputPossibleValues<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
) 

When property propertyName of class Class has input type 'select', this function returns the possible values allowed for the property.

isBuiltInTypeArrayProperty

function isBuiltInTypeArrayProperty<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if the property propertyName of class Class is an array of a built-in type (number[], string[], boolean[])

isMultipleSelectInput

function isMultipleSelectInput<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if the input rendered for the property propertyName of class Class should be a multiple select input.

isObjectProperty

function isObjectProperty<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if property propertyName of class Class is instance of a class or array of class instances.

isOptionalProperty

function isOptionalProperty<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if property propertyName of class Class is an optional property

removeUnchangedProperties

function removeUnchangedProperties<T extends Record<string, any>>(
  newInstance: T,
  currentInstance: T
)

When comparing properties of newInstance to currentInstance, if property value is the same in both, property will be removed from the newInstance.

shouldPropertyBePresent

function shouldPropertyBePresent<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T,
  serviceFunctionType: ServiceFunctionType
)

type ServiceFunctionType = 'create' | 'update' | 'other';

Tells if property propertyName of class Class should be present or not when instance of Classis given as an argument for service function of type serviceFunctionType.

getInputValidationProps

function getInputValidationProps<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
) 

Gets validation related properties for HTML input element for property propertyName of class Class. Validation related properties can include properties like minLength and maxLength etc...

getValidationMessage

function getValidationMessage(possibleErrorMessage: PossibleString): string

type PossibleString = string | null | undefined

Gets validation message from possibleErrorMessage. If property has not been validated, the possibleErrorMessage should be undefined and this function returns empty string. If property has been validated without error, possibleErrorMessage should be null and this function returns string 'OK'. In case of validation failure, this function returns the possibleErrorMessage

getValidationMessageHtmlClassName

function getValidationMessageHtmlClassNames(errorMessage: PossibleString)

type PossibleString = string | null | undefined

If errorMessage is string, returns 'validationMessage error', otherwise returns 'validationMessage'

validateServiceFunctionArgument

async function validateServiceFunctionArgument<T extends object>(
  serviceFunctionArgument: T | Partial<T>,
  ArgumentClass: new () => T,
  serviceFunctionType: ServiceFunctionType
): Promise<string | null>

type ServiceFunctionType = 'create' | 'update' | 'other';

Validates serviceFunctionArgument of class ArgumentClass when service function type is serviceFunctionType. On successful validation, returns Promise<null> and on validation failure returns promise of error message Promise<string>.

validateServiceFunctionArgumentOrThrow

async function validateServiceFunctionArgumentOrThrow<T extends object>(
  serviceFunctionArgument: T | Partial<T>,
  ArgumentClass: new () => T,
  serviceFunctionType: ServiceFunctionType
): Promise<void>

type ServiceFunctionType = 'create' | 'update' | 'other';

Validates serviceFunctionArgument of class ArgumentClass when service function type is serviceFunctionType. On successful validation, returns Promise<void> and on validation failure throws an exception.

validateServiceFunctionArgumentProperty

async function validateServiceFunctionArgumentProperty<
  T extends Record<string, any>,
  K extends keyof T,
  V extends T[K]
>(
  ArgumentClass: new () => T,
  propertyName: K,
  propertyValue: V,
  serviceFunctionType: ServiceFunctionType
): Promise<string | null>

type ServiceFunctionType = 'create' | 'update' | 'other';

Validates property value propertyValue of property propertyName of class ArgumentClass when service function type is serviceFunctionType. On successful validation, returns Promise<null> and on validation failure returns promise of error message Promise<string>.