Skip to content

Commit

Permalink
getFileType
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Oct 9, 2023
1 parent 44e9e3f commit 668f0e9
Show file tree
Hide file tree
Showing 12 changed files with 1,102 additions and 741 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.6.3
version: 8.8.0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.6.3
version: 8.8.0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.6.3
version: 8.8.0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change logs

## 2023.10.09 v5.11.0

1. new `getFileType` function, see: [getFileType](https://github.com/saqqdy/js-cool#getfiletype)
2. upgrade all packages

## 2023.09.23 v5.10.0

1. new `nextVersion` function, see: [nextVersion](https://github.com/saqqdy/js-cool#nextversion)
Expand Down
1 change: 1 addition & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const functionList = {
extend, // 深拷贝
delay, // 防抖节流
getType, // 获取目标类型
getFileType, // 根据链接后缀判断文件类型
cleanData, // 清洗数据
download, // 文件下载
searchObject, // 对象查找
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Collection of common JavaScript / TypeScript utilities
- [extend](#extend)
- [delay](#delay)
- [getType](#gettype)
- [getFileType](#getfiletype)
- [cleanData](#cleandata)
- [download](#download)
- [searchObject](#searchobject)
Expand Down Expand Up @@ -2458,6 +2459,42 @@ declare function getType<T = any>(
| 'null'
```

#### getFileType

Determine file type based on link suffix

- Since: `5.11.0`

- Arguments:

| Parameters | Description | Type | Optional | Required | Default |
| ---------- | ----------- | -------- | -------- | -------- | ------- |
| url | file url | `string` | - | `true` | - |

- Returns: `object`

- Example:

```ts
getFileType('/name.png')
// { "suffix": "png", "type": "image" }
getFileType('/name.PDF')
// { "suffix": "pdf", "type": "pdf" }
getFileType('/name.xyz')
// { "suffix": "xyz", "type": "other" }
```

- Types:

```ts
declare function getFileType(url: string): {
suffix: string
type: 'audio' | 'video' | 'image' | 'other' | 'word' | 'txt' | 'excel' | 'pdf' | 'ppt' | 'zip'
}
```

#### cleanData

Data cleaning methods
Expand Down
56 changes: 28 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "js-cool",
"description": "Collection of common JavaScript / TypeScript utilities",
"version": "5.10.0",
"packageManager": "pnpm@8.6.3",
"packageManager": "pnpm@8.8.0",
"main": "dist/index.cjs.js",
"module": "dist/index.esm-bundler.js",
"browser": "dist/index.esm-browser.js",
Expand Down Expand Up @@ -52,48 +52,48 @@
"mount-image": "^1.2.0",
"mount-script": "^1.2.0",
"mount-style": "^1.2.0",
"os-lang": "^3.1.1",
"os-lang": "^3.2.0",
"tslib": "^2.6.2",
"use-downloads": "^1.4.0"
"use-downloads": "^1.5.0"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.22.5",
"@eslint-sets/eslint-config-ts": "^5.8.0",
"@microsoft/api-extractor": "^7.36.4",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.0",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@types/activex-excel": "^14.0.6",
"@types/babel__core": "^7.20.1",
"@types/node": "^20.5.1",
"@babel/core": "^7.23.0",
"@babel/plugin-transform-runtime": "^7.22.15",
"@babel/preset-env": "^7.22.20",
"@babel/preset-typescript": "^7.23.0",
"@eslint-sets/eslint-config-ts": "^5.9.0",
"@microsoft/api-extractor": "^7.38.0",
"@rollup/plugin-alias": "^5.0.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.5",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@types/activex-excel": "^14.0.7",
"@types/babel__core": "^7.20.2",
"@types/node": "^20.8.3",
"babel-loader": "^9.1.3",
"core-js": "^3.32.1",
"core-js": "^3.33.0",
"cross-env": "^7.0.3",
"eslint": "^8.47.0",
"eslint": "^8.51.0",
"fast-glob": "^3.3.1",
"load-yml": "^1.3.0",
"load-yml": "^1.4.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.2",
"prettier": "^3.0.3",
"prettier-config-common": "^1.4.0",
"reinstaller": "^3.0.2",
"rm-all": "^1.1.1",
"rollup": "^3.28.0",
"rollup": "^4.0.2",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-filesize": "^10.0.0",
"rollup-plugin-polyfill-node": "^0.12.0",
"rollup-plugin-visualizer": "^5.9.2",
"tsnd": "^1.1.0",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.4",
"typescript": "^5.1.6",
"typedoc": "^0.25.2",
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.2.2",
"zx": "^7.2.3"
},
"engines": {
Expand Down
Loading

0 comments on commit 668f0e9

Please sign in to comment.