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

fordata

v1.0.5

Published

Easy handle data by prototype for TreeData、Array、Date、Encode、String etc.

Downloads

22

Readme

ForData

Easy handle data by prototype for TreeData、Array、Date、Encode、String etc..

Install

  npm i fordata //or yarn add fordata

CDN

  <script src="https://unpkg.com/fordata/dist/index.min.js"></script>

Usage

  • Tree

const { Tree } = require("fordata")
new Tree({
  id: 'id',
  parentId: 'pid',
  label: 'name',
  children: 'child'
})
let tree = [{
  name: '-一级 1',
  id: '一级 1',
  z: 1,
  child: [{
    name: '-二级 1-1',
    id: '二级 1-1',
    z: 3,
    child: [{
      name: '-三级 1-1-1',
      id: '三级 1-1-1',
      z: 2
    }]
  }]
}, {
  name: '-一级 2',
  id: '一级 2',
  child: [{
    name: '-二级 2-1',
    id: '二级 2-1',
    child: [{
      name: '-三级 2-1-1',
      id: '三级 2-1-1'
    }]
  }, {
    name: '-二级 2-2',
    id: '二级 2-2',
    child: [{
      name: '-三级 2-2-1',
      id: '三级 2-2-1'
    }]
  }]
}, {
  name: '-一级 3',
  id: '一级 3',
  child: [{
    name: '-二级 3-1',
    id: '二级 3-1',
    child: [{
      name: '-三级 3-1-1',
      id: '三级 3-1-1'
    }]
  }, {
    name: '-二级 3-2',
    id: '二级 3-2',
    child: [{
      name: '-三级 3-2-1',
      id: '三级 3-2-1'
    }]
  }]
}]
  • toArray(parentId)

    • {String|Number} parentId
      tree.toArray()
  • toTree(parentId)

    • {String|Number} parentId
      tree.toArray().toTree()
  • findPath(id)

    • {String|Number} id required
      tree.findPath('三级 3-1-1')
  • findChildren(id)

    • {String|Number} id required
      tree.findPath('一级 3')
  • DateTime

const { DateTime } = require("fordata")
new DateTime()
  • format()
  new Date().format('yyyy-MM-dd hh:mm:ss')
  // 2023-07-29 11:48:17
  • prev()
    • {Number} timestamp
      new Date().prev(1e3 * 60 * 60 * 24)
      // 2023-07-28 11:48:17
  • prevDay()
    • {Object} options
    • {Number} options.day
    • {Boolean} options.isShowAll = false
    • {Boolean} options.includeCurrent = false
      new Date().prevDay({ day: 5 })
      // 2023-07-24 11:48:17
      new Date().prevDay({ day: 5, isShowAll: true })
      // [
      //   '2023-07-24 11:48:17',
      //   '2023-07-25 11:48:17',
      //   '2023-07-26 11:48:17',
      //   '2023-07-27 11:48:17',
      //   '2023-07-28 11:48:17' 
      // ]
      new Date().prevDay({ day: 5, isShowAll: true, includeCurrent: true })
      // [
      //   '2023-07-25 11:48:17',
      //   '2023-07-26 11:48:17',
      //   '2023-07-27 11:48:17',
      //   '2023-07-28 11:48:17',
      //   '2023-07-29 11:48:17'
      // ]
  • prevMonth()
    • {Object} options
    • {Number} options.month
    • {Boolean} options.isShowAll = false
    • {Boolean} options.includeCurrent = false
      new Date().prevMonth({ month: 5, includeCurrent: false, isShowAll: true })
      // [
      // '2023-08-31 14:57:02',
      // '2023-09-30 14:57:02',
      // '2023-10-31 14:57:02',
      // '2023-11-30 14:57:02',
      // '2023-12-31 14:57:02'
      // ]
  • prevYear()
    • {Object} options
    • {Number} options.year
    • {Boolean} options.isShowAll = false
    • {Boolean} options.includeCurrent = false
      new Date().prevYear({ year: 5, includeCurrent: false, isShowAll: true  })
      // [
      // '2018-07-29 14:57:57',
      // '2019-07-29 14:57:57',
      // '2020-07-29 14:57:57',
      // '2021-07-29 14:57:57',
      // '2022-07-29 14:57:57'
      // ]
  • next()
    • {Number} timestamp
      new Date().next(1e3 * 60 * 60 * 24)
      // 2023-07-30 14:58:50
  • nextDay()
    • {Object} options
    • {Number} options.day
    • {Boolean} options.isShowAll = false
    • {Boolean} options.includeCurrent = false
      new Date().nextDay({ day: 5 })
      // 2023-08-03 14:59:09
      new Date().nextDay({ day: 5, isShowAll: true })
      // [
      //  '2023-07-30 14:59:28',
      //  '2023-07-31 14:59:28',
      //  '2023-08-01 14:59:28',
      //  '2023-08-02 14:59:28',
      //  '2023-08-03 14:59:28'
      // ]
      new Date().nextDay({ day: 5, isShowAll: true, includeCurrent: true })
      //[
      //  '2023-07-29 15:00:46',
      //  '2023-07-30 15:00:46',
      //  '2023-07-31 15:00:46',
      //  '2023-08-01 15:00:46',
      //  '2023-08-02 15:00:46'
      //]
  • nextMonth()
    • {Object} options
    • {Number} options.month
    • {Boolean} options.isShowAll = false
    • {Boolean} options.includeCurrent = false
      new Date().nextMonth({ month: 5, includeCurrent: false, isShowAll: true })
      //[
      //  '2023-08-31 15:01:24',
      //  '2023-09-30 15:01:24',
      //  '2023-10-31 15:01:24',
      //  '2023-11-30 15:01:24',
      //  '2023-12-31 15:01:24'
      //]
  • nextYear()
    • {Object} options
    • {Number} options.year
    • {Boolean} options.isShowAll = false
    • {Boolean} options.includeCurrent = false
      new Date().nextYear({ year: 5, includeCurrent: false, isShowAll: true  })
      //[
      //  '2023-07-29 15:01:53',
      //  '2024-07-29 15:01:53',
      //  '2025-07-29 15:01:53',
      //  '2026-07-29 15:01:53',
      //  '2027-07-29 15:01:53'
      //]
  • split()
    • {Object} options
    • {Date} options.startTime
    • {Date} options.endTime
    • {Number} options.gap milliseconds
      datetime.split({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-01-10 23:59:59'), gap: 1e3 * 60 * 60 * 24 })
      //[
      //  '2022-01-01 00:00:00',
      //  '2022-01-02 00:00:00',
      //  '2022-01-03 00:00:00',
      //  '2022-01-04 00:00:00',
      //  '2022-01-05 00:00:00',
      //  '2022-01-06 00:00:00',
      //  '2022-01-07 00:00:00',
      //  '2022-01-08 00:00:00',
      //  '2022-01-09 00:00:00',
      //  '2022-01-10 00:00:00'
      // ]
  • calc()
    • {Object} options
    • {Date} options.startTime
    • {Date} options.endTime
    • {type} options.type type values 'year' or 'day', default is 'year'
    • {Number} options.offset timezone offset, default is 8 (8 is China Timezone)
      datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') })
      // { year: 0, month: 10, day: 9, hour: 23, minutes: 59, seconds: 59 }
      datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') ,type : 'day'})
      // { day: 313, hour: 23, minutes: 59, seconds: 59 }
  • getWeek()
    • {Array} weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
      new Date().getWeek()
      // 星期日
      new Date().getWeek(['周日', '周一', '周二', '周三', '周四', '周五', '周六'])
      // 周日
  • getRangeYear()
      new Date().getRangeYear()
      // { start: '2023-01-01 00:00:00', end: '2023-12-31 23:59:59' }
  • getRangeMonth()
      new Date().getRangeMonth()
      // { start: '2023-07-01 00:00:00', end: '2023-07-31 23:59:59' }
  • getRangeWeek(startMonday = true)
      new Date().getRangeWeek()
      // { start: '2023-07-24 00:00:00', end: '2023-07-30 23:59:59' }
  • Encode

    const { Encode } = require("fordata")
    new Encode()
    • toBase64()
    "test".toBase64()
    • base64ToString()
    "dGVzdA==".toBase64()
    • toEntity()
    "test".toEntity()
    • entityToString()
    "&#116;&#101;&#115;&#116;".entityToString()
    • encodeURL()
    "http://test.com".encodeURL()
    • decodeURL()
    "http%3A%2F%2Ftest.com".decodeURL()
  • EasyArray

    const { EasyArray } = require("fordata")
    new EasyArray()
    • create()
    new Array.create(5, (i) => i + 1)
    • asc()
    [1, 2, 3, 4, 5, 1, 3, 4].asc()
    [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].asc('a')
    • desc()
    [1, 2, 3, 4, 5, 1, 3, 4].desc()
    [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].desc('a')
    • sum()
    [1, 2, 3, 4, 5, 1, 3, 4].sum()
    [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].sum('a')
    • unique()
    [1, 2, 3, 4, 5, 1, 3, 4].unique()
    [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].unique('a')
    • groupByLength()
    [1, 2, 3, 4, 5, 1, 3, 4].groupByLength(2)
    • groupByName()
    [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupByName('a')
  • EasyString

    const { EasyString } = require("fordata")
    new EasyString()
    • getInfoByIdCard()
    '510101199911111111'.getInfoByIdCard()
    // {
    //   areaCode: '510101',
    //   year: '1999',
    //  month: '11',
    //   day: '11',
    //  gender: 'male',
    //   age: 24
    // }