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

extension-props

v0.9.8

Published

A utility library delivering some additional utility functions.

Downloads

4

Readme

extension-props

A utility library delivering some additional utility functions.

Installation

npm install extension-props
# or
yarn add extension-props

Usage

You can use this utilities by two way:

  • Use utility functions through the provided objects likes ObjectType, ArrayType, ClassType, FunctionType, RegexType, StringType. (Recommend)

    const {
        ObjectType,
        ArrayType,
        ClassType,
        FunctionType,
        RegexType,
        StringType
    } = require('extension-props');
  • Load additional utility functions into global objects likes String, Function, Object, Array, RegExp.

    require('extension-props').extend();

String

  • forInstance(str): checks whether v is a string.
    • Variations:
      • StringType.forInstance(str)
      • String.forInstance(str)
  • isBlank(str): return true, if v string is blank.
    • Variations:
      • StringType.isBlank(str)
      • String.isBlank(str)
  • isNotBlank(str): return true, if v string is not blank.
    • Variations:
      • StringType.isBlank(str)
      • String.isBlank(str)
  • isEmpty(): checks a string is empty.
    • Variations:
      • StringType.valueOf(str).isEmpty()
      • String.prototype.isEmpty()
  • isNotEmpty(): checks a string is not empty.
    • Variations:
      • StringType.valueOf(str).isNotEmpty()
      • String.prototype.isNotEmpty()
  • equals(another): checks a string is equals with another string.
    • Variations:
      • StringType.valueOf(str).equals(another)
      • String.prototype.equals(another)
  • equalsIgnoreCase(another): checks a string is equals with another string on the basis of content of the string irrespective of case of the string.
    • Variations:
      • StringType.valueOf(str).equalsIgnoreCase(another)
      • String.prototype.equalsIgnoreCase(another)
  • replaceAll(str, search, replacement): returns a new string with all matches of a pattern replaced by a replacement.
    • Variations:
      • StringType.replaceAll(str, search, replacement)
      • String.replaceAll(str, search, replacement)
      • StringType.valueOf(str).replaceAll(search, replacement)
      • String.prototype.replaceAll(search, replacement)
  • replacePlaceholders(str, map): returns a new string with all matches of each key in the map replaced by its value.
    • Variations:
      • StringType.replacePlaceholders(str, map)
      • String.replacePlaceholders(str, map)
      • StringType.valueOf(str).replacePlaceholders(map)
      • String.prototype.replacePlaceholders(map)

Function

  • forInstance(func): checks whether f is a function.
    • Variations:
      • FunctionType.forInstance(func)
      • Function.functionForInstance(func)
  • defineFunction(name, prototype): define a function with dynamic name.
    • Variations:
      • FunctionType.defineFunction(name, prototype)
      • Function.defineFunction(name, prototype)
      • FunctionType.valueOf(prototype).defineFunction(name)
      • Function.prototype.defineFunction(name)
    • name: is the name of the function.
    • prototype (option): is a function that determines the content of the function being created.
    • returns a function.
  • isCallable(func): checks whether f function is callable.
    • Variations:
      • FunctionType.isCallable(func)
      • Function.isCallable(func)
  • isNormalFunction(func): checks whether f is a normal function, that means that f is not an async function nor an arrow function.
    • Variations:
      • FunctionType.isNormalFunction(func)
      • Function.isNormalFunction(func)
  • isAsyncFunction(func): checks whether f is an async function.
    • Variations:
      • FunctionType.isAsyncFunction(func)
      • Function.isAsyncFunction(func)
  • isSyncFunction(func): checks whether f is a sync function (negative of isAsyncFunction).
    • Variations:
      • FunctionType.isSyncFunction(func)
      • Function.isSyncFunction(func)
  • isArrowFunction(func): checks whether f is an arrow function.
    • Variations:
      • FunctionType.isArrowFunction(func)
      • Function.isArrowFunction(func)
  • isNonArrowFunction(func): negative of isArrowFunction.
    • Variations:
      • FunctionType.isNonArrowFunction(func)
      • Function.isNonArrowFunction(func)
  • clone(): clone a function.
    • Variations:
      • FunctionType.valueOf(func).clone()
      • Function.prototype.clone()

Class

  • forInstance(cls): checks whether c is a class.
    • Variations:
      • ClassType.forInstance(cls)
      • Function.classForInstance(cls)
  • defineClass(name, superclass, prototype): define a class with dynamic name.
    • Variations:
      • ClassType.defineClass(name, superclass, prototype)
      • Function.defineClass(name, superclass, prototype)
      • ClassType.valueOf(superclass).defineClass(name, prototype)
      • Function.prototype.defineClass(name, prototype)
    • name: is the name of the class.
    • superclass (option): specify a super class.
    • prototype (option): is a function that determines the content of constructor of the class being created.
    • return a class.
  • isES6Class(cls): checks whether c is an es6 class.
    • Variations:
      • ClassType.isES6Class(cls)
      • Function.isES6Class(cls)
  • preventInheritingClass(obj, classDefinition, except): prevent inheriting class.
    • Variations:
      • ClassType.preventInheritingClass(obj, classDefinition, except)
      • Object.preventInheritingClass(obj, classDefinition, except)
      • ClassType.valueOf(obj).preventInheritingClass(classDefinition, except)
      • Object.prototype.preventInheritingClass(classDefinition, except)
    • obj: is an instance of subclass of classDefinition class.
    • classDefinition: is a superclass.
    • except (option): is white list, designate classes that are allowed to inherit.
    • throw a OverridingError exception, if obj is an instance of a class, and it is not allowed to inherit the classDefinition class.
    • return false, if obj is an instance of a class, and it is not subclass of classDefinition class.
    • return true, if obj is an instance of a class, and it is allowed to inherit the classDefinition class.
    • Recommended: Put this function into the constructor.
  • preventOverrideFunction(obj, classDefinition, functions): prevent overriding of functions.
    • Variations:
      • ClassType.preventOverrideFunction(obj, classDefinition, functions)
      • Object.preventOverrideFunction(obj, classDefinition, functions)
      • ClassType.valueOf(obj).preventOverrideFunction(classDefinition, functions)
      • Object.prototype.preventOverrideFunction(classDefinition, functions)
    • obj: is an instance of subclass of classDefinition class.
    • classDefinition: is a superclass.
    • functions: is an array of functions need to prevent override.
    • throw a OverridingError exception, if obj contains a function, and it is not allowed to override in the subclass of the classDefinition class.
    • return false, if obj is an instance of a class, and it is not subclass of classDefinition class.
    • return true, if no function is prevented, it is contained in subclasses.
    • Recommended: Put this function into the constructor.

Object

  • getAllPropertyNames(obj): returns an array of all properties of a given object.
    • Variations:
      • ObjectType.getAllPropertyNames(obj)
      • Object.getAllPropertyNames(obj)
  • getAllPropertyDescriptor(obj, prop): returns a property descriptor for a property of a given object.
    • Variations:
      • ObjectType.getAllPropertyDescriptor(obj, prop)
      • Object.getAllPropertyDescriptor(obj, prop)
  • getAllPropertyDescriptors(obj): returns an array of all property descriptors of a given object.
    • Variations:
      • ObjectType.getAllPropertyDescriptors(obj)
      • Object.getAllPropertyDescriptors(obj)
  • isBlank(obj): return true, if obj = undefined or obj = null.
    • Variations:
      • ObjectType.isBlank(obj)
      • Object.isBlank(obj)
  • isNotBlank(obj): return true, if obj != undefined and obj != null.
    • Variations:
      • ObjectType.isNotBlank(obj)
      • Object.isNotBlank(obj)

Regex

  • forInstance(reg): checks whether v is a regex.
    • Variations:
      • RegexType.forInstance(reg)
      • RegExp.forInstance(reg)
  • escape(str): escape regex expression special characters.
    • Variations:
      • RegexType.escape(str)
      • RegExp.escape(str)
  • matchWords(str): create a regex string for checks match with the words in str string.
    • Variations:
      • RegexType.matchWords(str)
      • RegExp.matchWords(str)

Array

  • forInstance(arr): checks whether v is a array.
    • Variations:
      • ArrayType.forInstance(arr)
      • Array.forInstance(arr)
  • isBlank(arr): return true, if v array is blank.
    • Variations:
      • ArrayType.isBlank(arr)
      • Array.isBlank(arr)
  • isNotBlank(arr): return true, if v array is not blank.
    • Variations:
      • ArrayType.isNotBlank(arr)
      • Array.isNotBlank(arr)
  • isEmpty(): checks a array is empty.
    • Variations:
      • ArrayType.valueOf(str).isEmpty()
      • Array.prototype.isEmpty()
  • isNotEmpty(): checks a array is not empty.
    • Variations:
      • ArrayType.valueOf(str).isNotEmpty()
      • Array.prototype.isNotEmpty()
  • equals(another): checks a array is equals with another array.
    • Variations:
      • ArrayType.valueOf(str).equals(another)
      • Array.prototype.equals(another)
  • virtualGet(index): get value at index. You will still get a value even if the index is out of bounds.
    • Variations:
      • ArrayType.valueOf(str).virtualGet(index)
      • Array.prototype.virtualGet(index)
  • insert(index, ...elements): insert elements into the specified position.
    • Variations:
      • ArrayType.valueOf(str).insert(index, ...elements)
      • Array.prototype.insert(index, ...elements)
  • lastIndexOf(element): returns the last index at which a given element can be found in the array, or -1 if it is not present.
    • Variations:
      • ArrayType.valueOf(str).lastIndexOf(element)
      • Array.prototype.lastIndexOf(element)