Giter Club home page Giter Club logo

utils's Introduction

@extremejs/utils

Modern TypeScript utilities inspired by lodash, aiming to be high performance while having minimal size impact.

Test CodeCov Security License NPM Version NPM Monthly Downloads NPM Total Downloads NPM Bundle Size (Minified + GZip) NPM Bundle Size (Minified) Built with TypeScript Tested With Jest Open GitHub Issues Open GitHub Pull Requests Github Stars Github Forks

Table of Content

Installation

NPM

npm i @extremejs/utils

PNPM

pnpm add @extremejs/utils

Yarn

yarn add @extremejs/utils

Usage

import { sumByFn, sumByProperty, sumBy } from "@extremejs/utils";
// or
import { sumByFn, sumByProperty, sumBy } from "@extremejs/utils/sum-by-fn";

const sum1 = sumByFn([{ a: 1 }, { a: 2 }, { a: 3 }], ({ a }) => a); // => 6
// or
const sum2 = sumByProperty([{ a: 1 }, { a: 2 }, { a: 3 }], "a"); // => 6
// or
const sum3 = sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], ({ a }) => a); // => 6
// or
const sum4 = sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], "a"); // => 6

API usage documents are available here.

Notes

  1. Although this package is inspired by lodash, the method names might not be exactly the same or have different usage API, so make sure to read the docs first before using it.
  2. The methods do not type check at runtime (e.g. The Array chunk method assumes the size parameter is always a valid positive integer) so make sure you pass the correct values based on the documents/typescript types.

Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

utils's People

Contributors

ardalanamini avatar dependabot[bot] avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar

utils's Issues

feat: Add `mean` method

Contact Details

No response

What do you need?

This method should compute the mean of the numbers.

Purposed definition:

function mean(numbers: number[]): number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isDate` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a date or not.

Purposed definition:

function isDate(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `slice` method

Contact Details

No response

What do you need?

This method should create a slice of the value (array/string) from start, up to, but not including, end.

Purposed definition:

function slice(value: string | unknown[], start: number = 0, end: number = value.length): string | unknown[];

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `kebabCase` method

Contact Details

No response

What do you need?

This method should convert the given string to kebab case.

Purposed definition:

function kebabCase(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isPlainObject` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a plain object or not.

Purposed definition:

function isPlainObject(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isFunction` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a function or not.

Purposed definition:

function isFunction(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isObject` method

Contact Details

No response

What do you need?

This method determines whether the provided value is an object or not.

Purposed definition:

function isObject(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `camelCase` method

Contact Details

No response

What do you need?

This method should convert the given string to camel case.

Purposed definition:

function camelCase (string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `chunk` method

Contact Details

No response

What do you need?

This method should create an array of elements split into groups the length of size. If the array can't be split evenly, the final chunk will be the remaining elements.

Purposed definition:

function chunk(array: unknown[], size: number = 1): unknown[][];

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `repeat` method

Contact Details

No response

What do you need?

This method repeats the given string count times.

Purposed definition:

function repeat(string: string, count: number): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `sumByProperty` method

Contact Details

No response

What do you need?

This method should iterate through each of the provided values array and add the value of each element's property to produce the desired sum.

Purposed definition:

function sumByProperty<Value>(values: Value[], property: PropertyT): number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `endsWith` method

Contact Details

No response

What do you need?

This method should check whether the string ends with the given searchString string.

Purposed definition:

function endsWith(string: string, searchString: string, position?: number): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `meanByProperty` method

Contact Details

No response

What do you need?

This method should compute the mean of the values returned by the property for each element in the array.

Purposed definition:

function meanByProperty(array: unknown[], property: string): number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `lowerFirst` method

Contact Details

No response

What do you need?

This method should convert the first character of the string to lower case.

Purposed definition:

function lowerFirst(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isRegExp` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a RegExp istance or not.

Purposed definition:

function isRegExp(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `concat` method

Contact Details

No response

What do you need?

This method should create a new array concatenating the input array with any additional arrays and/or values.

Purposed definition:

function concat(array: unknown[], ...values: unknown[][]): unknown[];

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isFinite` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a finite number or not.

Purposed definition:

function isFinite(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `toPath` method

Contact Details

No response

What do you need?

This method should convert the provided property to an array of keys that'll represent the path of a value in an object.

Purposed definition:

function toPath<Property extends PropertyT>(property: Property): PathT<Property>;

type PropertyT = PropertyKey;

type PathT<Property extends PropertyT> = Property extends ""
  ? []
  : Property extends number
    ? [Property]
    : Property extends symbol
      ? [Property]
      : Property extends `${ infer First }.${ infer Rest }`
        ? [...PathT<First>, ...PathT<Rest>]
        : Property extends `${ infer First }[${ infer Rest }`
          ? [...PathT<First>, ...PathT<Rest>]
          : Property extends `${ infer First }][${ infer Rest }`
            ? [...PathT<First>, ...PathT<Rest>]
            : Property extends `${ infer Last }]`
              ? [Last]
              : [Property];

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `get` method

Contact Details

No response

What do you need?

This method should return the desired value based on the provided property.

Purposed definition:

function get(value: unknown, property: PropertyT, fallback: unknown): unknown;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `lowerCase` method

Contact Details

No response

What do you need?

This method should convert the given string to lowercase.

Purposed definition:

function lowerCase(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isInteger` method

Contact Details

No response

What do you need?

This method determines whether the provided value is an integer or not.

Purposed definition:

function isInteger(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isError` method

Contact Details

No response

What do you need?

This method determines whether the provided value is an error or not.

Purposed definition:

function isError(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `startsWith` method

Contact Details

No response

What do you need?

This method should check whether the string starts with the given searchString string.

Purposed definition:

function startsWith(string: string, searchString: string, position?: number): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isNumber` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a number or not.

Purposed definition:

function isNumber(value: unknown): value is number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isNil` method

Contact Details

No response

What do you need?

This method determines whether the provided value is null/undefined or not.

Purposed definition:

function isNil(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `replace` method

Contact Details

No response

What do you need?

This method replaces matches for the pattern in the string with the replacement.

Purposed definition:

function replace(string: string, pattern: RegExp | string, replacement: Function | string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `upperFirst` method

Contact Details

No response

What do you need?

This method should convert the first character of the string to upper case.

Purposed definition:

function upperFirst(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isBuffer` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a buffer or not.

Purposed definition:

function isBuffer(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `join` method

Contact Details

No response

What do you need?

This method should convert all elements in the array into a string separated by the separator.

Purposed definition:

function join(array: unknown[], separator: string = ""): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isNaN` method

Contact Details

No response

What do you need?

This method determines whether the provided value is NaN or not.

Purposed definition:

function IsNaN(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isString` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a string or not.

Purposed definition:

function isString(value: unknown): value is string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `sumByFn` method

Contact Details

No response

What do you need?

This method should iterate through each of the provided values array, by the provided iteratee function and add the resulting numbers returned by the said iteratee function to produce the desired sum.

Purposed definition:

function sumByFn<Value>(values: Value[], iteratee: (value: Value) => number): number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `compact` method

Contact Details

No response

What do you need?

This method should filter out the falsey values from the provided array.

Purposed definition:

function compact<Value>(array: Value[]): Array<CompactT<Value>>;

export type CompactT<Value> = Value extends ""
  ? never
  : Value extends 0
    ? never
    : Value extends false
      ? never
      : Value extends null
        ? never
        : Value extends undefined
          ? never
          : Value extends typeof NaN
            ? never
            : Value;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isNull` method

Contact Details

No response

What do you need?

This method determines whether the provided value is null or not.

Purposed definition:

function isNull(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `meanByFn` method

Contact Details

No response

What do you need?

This method should compute the mean of the values returned by the iteratee for each element in the array.

Purposed definition:

function meanByFn(array: unknown[], iteratee: (value: unknown) => number): number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isEven` method

Contact Details

No response

What do you need?

This method determines whether the provided number is an even number or not.

Purposed definition:

function isEven(number: number): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `split` method

Contact Details

No response

What do you need?

This method should split string by separator.

Purposed definition:

function split(string: string, separator: string | RegExp, limit?: number): string[];

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `first` method

Contact Details

No response

What do you need?

This method should return the first element of the value.

Purposed definition:

function first<Value extends unknown[] | string>(value: Value): Value;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isSymbol` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a symbol or not.

Purposed definition:

function isSymbol(value: unknown): value is symbol;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `snakeCase` method

Contact Details

No response

What do you need?

This method should convert the given string to snake case.

Purposed definition:

function snakeCase(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isUndefined` method

Contact Details

No response

What do you need?

This method determines whether the provided value is undefined or not.

Purposed definition:

function isUndefined(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `tail` method

Contact Details

No response

What do you need?

This method should return all but the first element of the value.

Purposed definition:

function tail<Value extends unknown[] | string>(value: Value): Value;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `sum` method

Contact Details

No response

What do you need?

This method should add the provided numbers to produce the desired sum.

Purposed definition:

function sum(numbers: number[]): number;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isArray` method

Contact Details

No response

What do you need?

This method determines whether the provided value is an array or not.

Purposed definition:

const isArray = Array.isArray;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isBoolean` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a boolean or not.

Purposed definition:

function isBoolean(value: unknown): value is boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `isSafeInteger` method

Contact Details

No response

What do you need?

This method determines whether the provided value is a safe integer or not.

Purposed definition:

function isSafeInteger(value: unknown): boolean;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `capitalize` method

Contact Details

No response

What do you need?

This method should convert the first character of the string to upper case and the remaining to lower case.

Purposed definition:

function capitalize(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `upperCase` method

Contact Details

No response

What do you need?

This method should convert the given string to uppercase.

Purposed definition:

function upperCase(string: string): string;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `head` method

Contact Details

No response

What do you need?

This method should return all but the last element of the value.

Purposed definition:

function head<Value extends unknown[] | string>(value: Value): Value;

Code of Conduct

  • I agree to follow this project's Code of Conduct

feat: Add `last` method

Contact Details

No response

What do you need?

This method should return the last element of the value.

Purposed definition:

function last<Value extends unknown[] | string>(value: Value): Value;

Code of Conduct

  • I agree to follow this project's Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.