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

@vue-formily/util

v0.1.3

Published

Common JavaScript utility library with performance, lightweight.

Downloads

112

Readme

Vue Formily Util

Common JavaScript utility library with performance, lightweight.

Getting Started

Installation

# install with yarn
yarn add @vue-formily/util

# install with npm
npm install @vue-formily/util --save

Utilities

isNullOrUndefined

Returns true if value is null or undefined.

isNullOrUndefined(value: any): boolean;

isPlainObject

Strict object type check. Only returns true for plain JavaScript objects.

isPlainObject(value: any): boolean;

isUndefined

Returns true if value has type number.

isUndefined(value: any): boolean;

isNumber

Returns true if value has type number.

isNumber(value: any): boolean;

isString

Returns true if value has type string.

isString(value: any): boolean;

isNumeric

Check if the input string contains only numeric characters.

isNumeric(value: string): boolean;

// Examples:
isNumeric('123'); // true
isNumeric('123.12'); // true
isNumeric('.12'); // true
isNumeric('-.12'); // true
isNumeric('-12.12'); // true
isNumeric('12e12'); // true
isNumeric(NaN); // false
isNumeric(null); // false
isNumeric([]); // false
isNumeric({}); // false
isNumeric(undefined); // false

isFunction

Returns true if value is a function.

isFunction(value: string): boolean;

isEmpty

Returns true if the object is empty. Empty is defined as:

  • null
  • undefined
  • a string with zero length
  • an array with no elements
  • a collection with no elements
isEmpty(value: any): boolean;

// Examples:
isEmpty(null); // true
isEmpty(undefined); // true
isEmpty(false); // false
isEmpty([]); // true
isEmpty({}); // true
isEmpty({ a: 1 }); // false
isEmpty([1]); // false
isEmpty(''); // true
isEmpty(' '); // false

isEqual

Returns true if 2 passed values are equal

isEqual(value: any): boolean;

// Examples:
isEqual(1, 1); // true
isEqual('1', '1'); // true
isEqual(undefined, undefined); // true
isEqual(null, undefined); // false
isEqual(new Date('01/04/2022'), new Date('01/04/2022')); // true
isEqual(new Date('01/04/2022'), new Date('01/04/2023')); // false
isEqual(
    {
      a: 1,
      b: {
        c: [1]
      }
    },
    {
      a: 1,
      b: {
        c: [1]
      }
    }
  )
); // true
isEqual(
    {
      a: 1,
      b: {
        c: [1]
      }
    },
    {
      a: 1,
      b: {
        c: [1, 2]
      }
    }
  )
); //false
isEqual([1, { a: 1 }], [1, { a: 1 }]); // true
isEqual([1, { a: 1, b: 2 }], [1, { b: 2, a: 1 }]); // true

merge

Merge objects or arrays

merge(target: any, ...sources: any[]): any;

// Examples:
merge({}, { test: 1, test2: [{ a: 1 }, 1] }, { test2: [{ b: 1 }] }); // { test: 1, test2: [{ a: 1, b: 1 }, 1] }
merge([1, { a: 1}], [2, { a: 2, b: 1 }, 3]); // [2, { a: 2, b: 1 }, 3]

get

Find the first found value in objects or arrays by its path.

get(path: string | string[], ...args: any[]): any;

// Examples:
get('a.b[1]', { a: { b: [1, 3] } }); // 3
get('[1]', [1], [2, 3]); // 3

findIndex

Returns the index of the first element in the array that satisfies the provided testing function, ortherwise, returns -1.

findIndex(arr: any[] = [], fn: (...args: any[]) => boolean): number;

// Examples:
findIndex([1, 2], n => n === 2); // 1
findIndex([null, { a: 1 }], n => n && n.a === 1); // 3

flatArray

Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

flatArray(arr: any[], deep = Infinity): any[];

// Examples:
flatArray([1, [2], [3, [4]]]) // [1, 2, 3, 4]

interpolate

Simple string formatter.

flatArray(arr: any[], deep = Infinity): any[];

// Examples:
interpolate('{a[b]} {a[c][d]} {value} test', {
  value: 1,
  a: {
    b: 'test',
    c: {
      d: 'aaa'
    }
  }
}) // test aaa 1 test

interpolate('{a.b} {a.c.d} {value} test', {
  value: 1,
  a: {
    b: 'test',
    c: {
      d: 'aaa'
    }
  }
}) // test aaa 1 test

interpolate('{a.b} {a.c[d]} {a.d[2]} {value} test', {
  value: 1,
  a: {
    b: 'test',
    c: {
      d: 'aaa'
    },
    d: [1, 2, 3]
  }
}) // test aaa 3 1 test

Contributing

You are welcome to contribute to this project.

License

MIT