Giter Site home page Giter Site logo

node-utils's Introduction

@ipoa/utils

npm version plugin version install size

install

npm install @ipoa/utils --save

Example

// Determine if a value is an Array
var utils = require('@ipoa/utils')
console.log(utils.isArray([1, 2, 3])) // true

// merges the properties of each object and returns result. 
var result = utils.merge({ foo1: 123 }, { foo1: 456 }, { foo2: 789 })
console.log(result); // outputs { foo1: 456, foo2: 789 }

utils.extend(utils, {
  /**
   * Compose the `User-Agent` content
   *
   * @returns {string} - The `User-Agent` value
   */
  userAgent: function () {
    const { name: pkgName, version: pkgVersion } = require('../package.json')
    const { platform, arch, versions: { node: nodeVersion } } = process

    return `${pkgName}/${pkgVersion} node/${nodeVersion} ${platform}/${arch}`
  },
})
module.exports = utils

// getUrlParams
var url = 'http://xxx.xxx.com/?id=1&start=0&count=10'
var result = utils.getUrlParams(url);
console.log(result); // outputs { id: '1', start: '0', count: '10' }

Features

  • Determine if a value is undefined:isUndefined
  • Determine if a value is a Buffer:isBuffer
  • Determine if a value is an ArrayBuffer:isArrayBuffer
  • Determine if a value is a FormData:isFormData
  • Determine if a value is a view on an ArrayBuffer:isArrayBufferView
  • Determine if a value is a String:isString
  • Determine if a value is a Number:isNumber
  • Determine if a value is an Object:isObject
  • Determine if a value is a plain Object:isPlainObject
  • Determine if a value is an JSON:isJSON
  • Determine if a value is a Date:isDate
  • Determine if a value is a File:isFile
  • Determine if a value is a Blob:isBlob
  • Determine if a value is a Function:isFunction
  • Determine if a value is a Stream:isStream
  • Determine if a value is a URLSearchParams object:isURLSearchParams
  • Trim excess whitespace off the beginning and end of a string:trim
  • Determine if we're running in a standard browser environment:isProcessEnv
  • Similar to isStandardBrowserEnv, just check it's running in a Node environment
  • Determine if a value is a form-data node module
  • Iterate over an Array or an Object invoking a function for each item:forEach
  • merges the properties of each object and returns result:merge
  • Extends object a by mutably adding to it the properties of object b:extend
  • Remove byte order marker. This catches EF BB BF (the UTF-8 BOM):stripBOM
  • Parse parameters from URL:getUrlParams

Unit Testing

To run the tests for should simply run:

npm install && npm test

Resources

License

MIT

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.