{"id":19013337,"url":"https://github.com/z41z/fordata","last_synced_at":"2025-07-05T22:34:19.772Z","repository":{"id":208933723,"uuid":"722399426","full_name":"z41z/fordata","owner":"z41z","description":"Easy handle data by prototype for TreeData、Array、Date、Encode、String etc.","archived":false,"fork":false,"pushed_at":"2024-09-18T03:25:58.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T20:11:31.193Z","etag":null,"topics":["array","datetime","encode","prototype","string","treedata"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/z41z.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T04:08:20.000Z","updated_at":"2024-09-18T03:26:02.000Z","dependencies_parsed_at":"2024-09-12T18:21:29.853Z","dependency_job_id":null,"html_url":"https://github.com/z41z/fordata","commit_stats":null,"previous_names":["z41z/fordata"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Ffordata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z41z","download_url":"https://codeload.github.com/z41z/fordata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654030,"owners_count":21140235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","datetime","encode","prototype","string","treedata"],"created_at":"2024-11-08T19:23:27.163Z","updated_at":"2025-04-17T03:31:50.382Z","avatar_url":"https://github.com/z41z.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ForData\n\nEasy handle data by prototype for TreeData、Array、Date、Encode、String etc..\n\n## Install\n\n``` node\n  npm i fordata //or yarn add fordata\n```\n\n## CDN\n\n``` js\n  \u003cscript src=\"https://unpkg.com/fordata/dist/index.min.js\"\u003e\u003c/script\u003e\n```\n\n### Usage\n\n- #### Tree\n``` js\nconst { Tree } = require(\"fordata\")\nnew Tree({\n  id: 'id',\n  parentId: 'pid',\n  label: 'name',\n  children: 'child'\n})\nlet tree = [{\n  name: '-一级 1',\n  id: '一级 1',\n  z: 1,\n  child: [{\n    name: '-二级 1-1',\n    id: '二级 1-1',\n    z: 3,\n    child: [{\n      name: '-三级 1-1-1',\n      id: '三级 1-1-1',\n      z: 2\n    }]\n  }]\n}, {\n  name: '-一级 2',\n  id: '一级 2',\n  child: [{\n    name: '-二级 2-1',\n    id: '二级 2-1',\n    child: [{\n      name: '-三级 2-1-1',\n      id: '三级 2-1-1'\n    }]\n  }, {\n    name: '-二级 2-2',\n    id: '二级 2-2',\n    child: [{\n      name: '-三级 2-2-1',\n      id: '三级 2-2-1'\n    }]\n  }]\n}, {\n  name: '-一级 3',\n  id: '一级 3',\n  child: [{\n    name: '-二级 3-1',\n    id: '二级 3-1',\n    child: [{\n      name: '-三级 3-1-1',\n      id: '三级 3-1-1'\n    }]\n  }, {\n    name: '-二级 3-2',\n    id: '二级 3-2',\n    child: [{\n      name: '-三级 3-2-1',\n      id: '三级 3-2-1'\n    }]\n  }]\n}]\n```\n\n* toArray(parentId)\n  * {String|Number} parentId\n\n  ``` js\n    tree.toArray()\n  ```\n\n* toTree(parentId)\n  * {String|Number} parentId\n\n  ``` js\n    tree.toArray().toTree()\n  ```\n\n* findPath(id)\n  * {String|Number} id `required`\n\n  ``` js\n    tree.findPath('三级 3-1-1')\n  ```\n\n* findChildren(id)\n  * {String|Number} id `required`\n\n  ``` js\n    tree.findPath('一级 3')\n  ```\n\n- #### DateTime\n\n``` js\nconst { DateTime } = require(\"fordata\")\nnew DateTime()\n```\n\n  - ##### format()\n  ``` js\n    new Date().format('yyyy-MM-dd hh:mm:ss')\n    // 2023-07-29 11:48:17\n  ```\n  - ##### prev()\n     - {Number} timestamp  \n    ``` js\n      new Date().prev(1e3 * 60 * 60 * 24)\n      // 2023-07-28 11:48:17\n    ```\n  - ##### prevDay()\n    - {Object} options\n    - {Number} options.day\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().prevDay({ day: 5 })\n      // 2023-07-24 11:48:17\n      new Date().prevDay({ day: 5, isShowAll: true })\n      // [\n      //   '2023-07-24 11:48:17',\n      //   '2023-07-25 11:48:17',\n      //   '2023-07-26 11:48:17',\n      //   '2023-07-27 11:48:17',\n      //   '2023-07-28 11:48:17' \n      // ]\n      new Date().prevDay({ day: 5, isShowAll: true, includeCurrent: true })\n      // [\n      //   '2023-07-25 11:48:17',\n      //   '2023-07-26 11:48:17',\n      //   '2023-07-27 11:48:17',\n      //   '2023-07-28 11:48:17',\n      //   '2023-07-29 11:48:17'\n      // ]\n    ```\n  - ##### prevMonth()\n    - {Object} options\n    - {Number} options.month\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().prevMonth({ month: 5, includeCurrent: false, isShowAll: true })\n      // [\n      // '2023-08-31 14:57:02',\n      // '2023-09-30 14:57:02',\n      // '2023-10-31 14:57:02',\n      // '2023-11-30 14:57:02',\n      // '2023-12-31 14:57:02'\n      // ]\n    ```\n  - ##### prevYear()\n    - {Object} options\n    - {Number} options.year\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().prevYear({ year: 5, includeCurrent: false, isShowAll: true  })\n      // [\n      // '2018-07-29 14:57:57',\n      // '2019-07-29 14:57:57',\n      // '2020-07-29 14:57:57',\n      // '2021-07-29 14:57:57',\n      // '2022-07-29 14:57:57'\n      // ]\n    ```\n  - ##### next()\n    - {Number} timestamp  \n    ``` js\n      new Date().next(1e3 * 60 * 60 * 24)\n      // 2023-07-30 14:58:50\n    ```\n  - ##### nextDay()\n    - {Object} options\n    - {Number} options.day\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().nextDay({ day: 5 })\n      // 2023-08-03 14:59:09\n      new Date().nextDay({ day: 5, isShowAll: true })\n      // [\n      //  '2023-07-30 14:59:28',\n      //  '2023-07-31 14:59:28',\n      //  '2023-08-01 14:59:28',\n      //  '2023-08-02 14:59:28',\n      //  '2023-08-03 14:59:28'\n      // ]\n      new Date().nextDay({ day: 5, isShowAll: true, includeCurrent: true })\n      //[\n      //  '2023-07-29 15:00:46',\n      //  '2023-07-30 15:00:46',\n      //  '2023-07-31 15:00:46',\n      //  '2023-08-01 15:00:46',\n      //  '2023-08-02 15:00:46'\n      //]\n    ```\n  - ##### nextMonth()\n    - {Object} options\n    - {Number} options.month\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().nextMonth({ month: 5, includeCurrent: false, isShowAll: true })\n      //[\n      //  '2023-08-31 15:01:24',\n      //  '2023-09-30 15:01:24',\n      //  '2023-10-31 15:01:24',\n      //  '2023-11-30 15:01:24',\n      //  '2023-12-31 15:01:24'\n      //]\n    ```\n  - ##### nextYear()\n    - {Object} options\n    - {Number} options.year\n    - {Boolean} options.isShowAll = false\n    - {Boolean} options.includeCurrent = false\n    ``` js\n      new Date().nextYear({ year: 5, includeCurrent: false, isShowAll: true  })\n      //[\n      //  '2023-07-29 15:01:53',\n      //  '2024-07-29 15:01:53',\n      //  '2025-07-29 15:01:53',\n      //  '2026-07-29 15:01:53',\n      //  '2027-07-29 15:01:53'\n      //]\n    ```\n  - ##### split()\n    - {Object} options\n    - {Date} options.startTime\n    - {Date} options.endTime\n    - {Number} options.gap `milliseconds`\n    ``` js\n      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 })\n      //[\n      //  '2022-01-01 00:00:00',\n      //  '2022-01-02 00:00:00',\n      //  '2022-01-03 00:00:00',\n      //  '2022-01-04 00:00:00',\n      //  '2022-01-05 00:00:00',\n      //  '2022-01-06 00:00:00',\n      //  '2022-01-07 00:00:00',\n      //  '2022-01-08 00:00:00',\n      //  '2022-01-09 00:00:00',\n      //  '2022-01-10 00:00:00'\n      // ]\n    ```\n  - ##### calc()\n    - {Object} options\n    - {Date} options.startTime\n    - {Date} options.endTime\n    - {type} options.type `type values 'year' or 'day', default is 'year'`\n    - {Number} options.offset `timezone offset, default is 8 (8 is China Timezone)`\n    ``` js\n      datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') })\n      // { year: 0, month: 10, day: 9, hour: 23, minutes: 59, seconds: 59 }\n      datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') ,type : 'day'})\n      // { day: 313, hour: 23, minutes: 59, seconds: 59 }\n    ```\n  - ##### getWeek()\n    - {Array} weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']\n    ``` js\n      new Date().getWeek()\n      // 星期日\n      new Date().getWeek(['周日', '周一', '周二', '周三', '周四', '周五', '周六'])\n      // 周日\n    ```\n  - ##### getRangeYear()\n    ``` js\n      new Date().getRangeYear()\n      // { start: '2023-01-01 00:00:00', end: '2023-12-31 23:59:59' }\n    ```\n  - ##### getRangeMonth()\n    ``` js\n      new Date().getRangeMonth()\n      // { start: '2023-07-01 00:00:00', end: '2023-07-31 23:59:59' }\n    ```\n  - ##### getRangeWeek(startMonday = true)\n    ``` js\n      new Date().getRangeWeek()\n      // { start: '2023-07-24 00:00:00', end: '2023-07-30 23:59:59' }\n    ```  \n\n- #### Encode\n  ``` js\n  const { Encode } = require(\"fordata\")\n  new Encode()\n  ```\n  - ##### toBase64()\n  ``` js\n  \"test\".toBase64()\n  ```\n  - ##### base64ToString()\n  ``` js\n  \"dGVzdA==\".toBase64()\n  ```\n  - ##### toEntity()\n  ``` js\n  \"test\".toEntity()\n  ```\n  - ##### entityToString()\n  ``` js\n  \"\u0026#116;\u0026#101;\u0026#115;\u0026#116;\".entityToString()\n  ```\n  - ##### encodeURL()\n  ``` js\n  \"http://test.com\".encodeURL()\n  ```\n  - ##### decodeURL()\n  ``` js\n  \"http%3A%2F%2Ftest.com\".decodeURL()\n  ```\n- #### EasyArray\n  ``` js\n  const { EasyArray } = require(\"fordata\")\n  new EasyArray()\n  ```\n  - ##### create()\n  ``` js\n  new Array.create(5, (i) =\u003e i + 1)\n  ```\n  - ##### asc()\n  ``` js\n  [1, 2, 3, 4, 5, 1, 3, 4].asc()\n  [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].asc('a')\n  ```\n  - ##### desc()\n  ``` js\n  [1, 2, 3, 4, 5, 1, 3, 4].desc()\n  [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].desc('a')\n  ```\n  - ##### sum()\n  ``` js\n  [1, 2, 3, 4, 5, 1, 3, 4].sum()\n  [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].sum('a')\n  ```\n  - ##### unique()\n  ``` js\n  [1, 2, 3, 4, 5, 1, 3, 4].unique()\n  [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].unique('a')\n  ```\n  - ##### groupByLength()\n  ``` js\n  [1, 2, 3, 4, 5, 1, 3, 4].groupByLength(2)\n  ```\n  - ##### groupByName()\n  ``` js\n  [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupByName('a')\n  ```\n  - ##### groupByValue()\n  ``` js\n  [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupValue('a')\n  // { '1': [ { a: 1 }, { a: 1 } ], '2': [ { a: 2 } ], '3': [ { a: 3 } ] }\n  ```\n\n- #### EasyString\n  ``` js\n  const { EasyString } = require(\"fordata\")\n  new EasyString()\n  ```\n  - ##### getInfoByIdCard()\n  ``` js\n  '510101199911111111'.getInfoByIdCard()\n  // {\n  //   areaCode: '510101',\n  //   year: '1999',\n  //  month: '11',\n  //   day: '11',\n  //  gender: 'male',\n  //   age: 24\n  // }\n  ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz41z%2Ffordata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz41z%2Ffordata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz41z%2Ffordata/lists"}