Code Monkey home page Code Monkey logo

helpers.js's Introduction

@dongskyler/helpers.js

Homepage: https://github.com/dongskyler/helpers.js

npm version Node.js CI codecov CodeFactor DeepScan grade License: MIT

GitHub issues GitHub issues-closed GitHub pull-requests GitHub pull-requests closed


Table of contents


Description

This is a collections of JavaScript and TypeScript helper functions.


Functions

inputOutput

  • listFilesInDirSync()

    listFilesInDirSync(dir[, ext, removeExt])

    • Parameters
      • dir: string (Positional, required)
        • Path to directory.
      • ext: string | null (Positional, optional)
        • Filter by file extension.
      • removeExt: boolean (Positional, optional)
        • Remove the file extension from the filename string.
    • Return value: string[] | null
      • An array of filenames in a directory.
  • loadFile()

  • readPipeWrite()

  • writeToFile()

others

  • runFuncsWithArgs()

    runFuncsWithArgs(funcs[, args, spread])

    • Run an array of functions with the same set of argument(s)
    • Parameters
      • funcs: ((...args: any | any[] | null) => any)[] (Positional, required)
        • An array of functions.
      • args: any | any[] | null = null (Positional, optional)
        • An array of arguments. Each element of the array will be presented to each function.
      • spread: boolean (Positional, optional)
        • If args is an array of arrays, you can choose to expand each sub-array with the spread operator.
        • Default is false.
    • Return value: any[]
      • An array of return values from functions
  • valOfKeysAndIndices()

    valOfKeysAndIndices(obj[, key0[, key1[, ...keyN]]])

    • Returns the value in an array or an object (or you call it JSON, a hash map or a dictionary) given the series of indices and/or keys pointing to the value.
    • Parameters
      • obj: any (Positional, required)
        • An array, an object (or you call it JSON, a hash map or a dictionary) or a combination.
        • The first index or key pointing to the value is required.
      • keyN: string | number | null (Positional, optional)
        • An arbitrary number of indices and/or keys pointing to the value.
        • For example, if x = {name: 'Tom'}, to fetch value 'Tom', use valOfKeysAndIndicies(x, 'name'). If y = { key0: [{ key1: [3.142, 6.626,] },] }, to fetch 6.626, use valOfKeysAndIndicies(y, 'key0', 0, 'key', 1).
    • Return value: any
      • The value from the given indices/keys.

sort

  • comparatorLexic()

    comparatorLexic([{key = [], ignoreCase = false, descending = false})

    • Compare function for comparing lexicographic order.
    • Parameters
      • ignoreCase: boolean (Named, optional)
        • Ignore the case of the given string.
        • Default is false.
      • descending: boolean (Named, optional)
        • Ascending or descending order.
        • Default is false, that is, ascending order.
      • keyN: string | number | null (Positional, optional)
        • An arbitrary number of indices and/or keys pointing to the value for comparison.
        • For example, if x = {name: 'Tom'}, use comparatorLexic('name') to fetch value 'Tom' for comparison. If x = { key0: [{ key1: [Earth, Mars,] },] }, to fetch Mars for comparison, use comparatorLexic('key0', 0, 'key', 1).
        • See keyN in valOfKeysAndIndices for more details.
        • Default is null.
    • Return value: function
      • Function (x: any, y: any) => number
        • Return value: number
          • -1 if a should placed before b.
          • 0 if a and b are equal.
          • 1 if a should be placed after b.
  • comparatorNumeric()

    comparatorNumeric([{key = [], ignoreSign = false, descending = false})

    • Compare function for comparing numerical order.
    • Parameters
      • keyN: string | number | null (Positional, optional)
        • An arbitrary number of indices and/or keys pointing to the value for comparison.
        • If x = { key0: [{ key1: [3.142, 6.626,] },] }, to fetch 6.626 for comparison, use comparatorLexic('key0', 0, 'key', 1).
        • See keyN in valOfKeysAndIndices for more details.
        • Default is null.
      • ignoreSign: boolean (Named, optional)
        • Ignore the sign of the number, i.e. use the absolute value for comparison.
        • Default is false.
      • descending: boolean (Named, optional)
        • Ascending or descending order.
        • Default is false, that is, ascending order.
    • Return value: function
      • Function (a: any, b: any) => number
        • Return value: number
          • -1 if a should placed before b.
          • 0 if a and b are equal.
          • 1 if a should be placed after b.
  • bubbleSort()

    bubbleSort(arr[, compareFunction, k])

    • Bubble sort algorithm. Stable.
    • Parameters
      • arr: any[] (Positional, required)
        • An array to be sorted.
      • compareFunction: (a: any, b: any) => number (Positional, optional)
      • k: number (Positional, optional)
        • Partially sort the array to get the first k sorted elements
    • Return value: any[]
      • A sorted array.
  • mergeSort()

    mergeSort(arr[, compareFunction])

    • Merge sort algorithm. Stable.
    • Parameters
      • arr: any[] (Positional, required)
        • An array to be sorted.
      • compareFunction: (a: any, b: any) => number (Positional, optional)
    • Return value: any[]
      • A sorted array.
  • partialSort()

    partialSort(arr[, compareFunction, k])

    • Partially sort the array to get the first k sorted elements, given the compare function.

helpers.js's People

Contributors

dongskyler avatar dependabot[bot] avatar dependabot-preview[bot] avatar

Watchers

James Cloos avatar  avatar

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.