Skip to content

Commit

Permalink
chore: init template and add an example and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrbo committed Jul 25, 2022
0 parents commit d5cc3a7
Show file tree
Hide file tree
Showing 39 changed files with 4,248 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/docs/**/*.md
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@vtrbo"
}
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [vtrbo]
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Setup
run: npm i -g @vtrbo/ni

- name: Install
run: nci

- name: Lint
run: nr lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Setup
run: npm i -g @vtrbo/ni

- name: Install
run: nci

- name: Typecheck
run: nr typecheck

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: [14.x, 16.x]
os: [ubuntu-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Setup
run: npm i -g @vtrbo/ni

- name: Install
run: nci

- name: Build
run: nr build

- name: Test
run: nr test
34 changes: 34 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deployment

on:
push:
tags:
- 'v*'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Setup
run: npm i -g @vtrbo/ni

- name: Install
run: nci

- name: Build
run: 'nr docs:build'

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
cname: utils.vtrbo.cn
publish_branch: docs
publish_dir: ./docs/.vitepress/dist/
commit_message: Release by
github_token: ${{secrets.PERSONAL_ACCESS_TOKEN}}
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# Nuxt generate
dist

# Serverless directories
.serverless

# IDE
.idea

# history
.history

*.lerna_backup
*.vsix
temp
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-workspace-root-check = true
auto-install-peers = true
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"vitepress"
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Victor Bo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# utils
Collection of common JavaScript / TypeScript utils.
60 changes: 60 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { defineConfig } from 'vitepress'

export default defineConfig({
lang: 'zh-CN',
title: 'Victor Bo Utils',
description: 'Collection of common JavaScript or TypeScript utils.',

base: '/',
// lastUpdated: true,

head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }],
],

themeConfig: {
logo: '/logo.svg',

editLink: {
text: '为此页提供修改建议',
pattern: 'https://github.com/vtrbo/utils/edit/main/docs/:path',
},

socialLinks: [
{ icon: 'twitter', link: 'https://twitter.com/vtrbo88' },
{ icon: 'github', link: 'https://github.com/vtrbo/utils' },
],

localeLinks: {
text: '简体中文',
items: [],
},

footer: {
message: 'Released under the MIT License',
copyright: 'Copyright © 2022-present Victor Bo',
},

nav: [
{ text: '指引', link: '/guide/what-is-utils', activeMatch: '/guide/' },
{ text: '函数', link: '/function/', activeMatch: '/function/' },
],

sidebar: {
'/guide/': sideGuide(),
},
},
})

function sideGuide() {
return [
{
text: '基础',
collapsible: true,
items: [
{ text: '介绍', link: '/guide/what-is-utils' },
{ text: '快速上手', link: '/guide/get-started' },
],
},
]
}
1 change: 1 addition & 0 deletions docs/function/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 这是函数页面
56 changes: 56 additions & 0 deletions docs/guide/get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## npm 安装
目前安装 @vtrbo/utils 的方式,只有一种,那就是使用 npm 安装。<br>
这里我推荐全局安装 [@vtrbo/ni](https://github.com/vtrbo/ni/),它可以自动判断项目中的依赖锁文件,使用指定的管理器安装。
```shell
ni @vtrbo/utils

# or
npm install @vtrbo/utils
yarn add @vtrbo/utils
pnpm install @vtrbo/utils
```

## 使用
::: warning
并不是很推荐使用全部引入和模块引入,因为这将增大你的包体积。<br>
这里更推荐使用单个引入,这遵循了按需加载的原则。
:::

## 全部引入
```js
import utils from '@vtrbo/utils'

// module 为模块名称 function 为方法名
// 比如:字符串模块的随机字符串方法
// utils.string.randomString()
utils.module.function()
```

## 模块引入
```js
// module 为模块名称
// 比如:字符串模块
// import { string } from '@vtrbo/utils'
// or
// import string from '@vtrbo/utils/string'
import { module } from '@vtrbo/utils'
// or
import module from '@vtrbo/utils/module'

// module 为模块 function 为方法名
// 比如:字符串模块的随机字符串方法
// string.randomString()
module.function()
```

## 单个引入
```js
// module 为模块 function 为方法名
// 比如:字符串模块的随机字符串方法
// import { randomString } from '@vtrbo/utils/string'
import { function } from '@vtrbo/utils/module'

// 比如:字符串模块的随机字符串方法
// randomString()
function()
```
14 changes: 14 additions & 0 deletions docs/guide/what-is-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## 介绍
[@vtrbo/utils](https://npmjs.com/package/@vtrbo/utils/)[Victor Bo](https://github.com/vtrbo/) 的一个工具函数库。本着不重复造轮子的理念,库内包含的函数大多数为网络收集(标明的有出处),当然也有部分是自己实现的。

::: warning
@vtrbo/utils 目前处于 beta 阶段,内部的函数可能会发生一些变化,以至于可能会产生一些副作用。当然,已经发布的函数基本上会处于一个比较文档的状态,除非有一些特殊情况,比如出处的函数发生变化等。
:::

## 动机
::: danger
单纯的就是我不想每次碰到一个函数,都要去百度或者其他地方复制一遍下来<br>
单纯的就是我不想每次写函数的时候,都去复制或者引入一个库增大包的体积<br>
单纯的...<br>
好吧,我承认,单纯的就是我懒
:::
Loading

0 comments on commit d5cc3a7

Please sign in to comment.