diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index ed39c15..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release - -on: - workflow_dispatch: - push: - branches: - - main - -permissions: - contents: read - -jobs: - release: - name: Release - runs-on: ubuntu-latest - permissions: - contents: write - issues: write - pull-requests: write - id-token: write - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Setup Bun - uses: oven-sh/setup-bun@v2 - - name: Install dependencies - run: bun install - - name: Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: bun run semantic-release - - - diff --git a/.nvimrc b/.nvimrc new file mode 100644 index 0000000..a24992d --- /dev/null +++ b/.nvimrc @@ -0,0 +1 @@ +lts diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..574bb23 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +Github. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1419b19 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © + +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. diff --git a/README.md b/README.md index 9dd7cfe..3490a11 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,43 @@ -# lib.js +# 🧩 LibJS 🧩 -## Rules +[![Stars](https://img.shields.io/github/stars/gutenye/lib.js?style=social)](https://github.com/gutenye/lib.js) [![NPM Version](https://img.shields.io/npm/v/@gutenye/lib.js)](https://www.npmjs.com/package/@gutenye/lib.js) [![License](https://img.shields.io/github/license/gutenye/lib.js?color=blue)](https://github.com/gutenye/lib.js/blob/main/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue)](https://github.com/gutenye/lib.js#-contribute) + +Javascript utils that you can copy and paste into your projects. + +**Show your and support by starring this project and following the author, [Guten Ye](https://github.com/gutenye)!** + +## 🌟 Design Goals + +This is NOT a library. It's a collection of re-usable code that you can copy and paste into your apps. You do not install it as a dependency. It is not available or distributed via npm. +Pick the code you need. Copy and paste the code into your project and customize to your needs. The code is yours. - Drop-in replacement - Copy & paste only, do not publish the package. - Naming: Can use same name if it's a drop-in replacement, otherwsie use a different name -## Usage +## 📖 List of Utils + +- [fs](./fs/README.md) +- [js](./js/README.md) +- [fetch](./fetch/README.md) +- [child_process](./child_process/README.md) +- [raycast](./raycast/README.md) + +## 🤝 Contribute + +We welcome contributions! Whether it’s bug reports, feature suggestions, or pull requests, your involvement makes this project better. + +**How to Contribute:** + +1. Fork the Repository +2. Open a Pull Request on Github + +--- + +Thank you for using LibJS! ✨ If you found it helpful, please ⭐️ star the project ️️⭐ on GitHub. If you have any questions or encounter issues, please refer to the documentation or report an issue on GitHub. + +**Special thanks to all the contributors:** + +[![](https://contrib.rocks/image?repo=gutenye/lib.js)](https://github.com/gutenye/lib.js/graphs/contributors) -``` -import fs from '#/utils/fs' -import { spawnPlus } from '#/utils/childProcess' -import { request, createRequest } from '#/utils/fetch' -import { isString } from '#/utils/js' -``` +[⬆ Back to top ⬆](#readme) diff --git a/ake b/ake old mode 100755 new mode 100644 index 895f04a..c966014 --- a/ake +++ b/ake @@ -1,5 +1,20 @@ -#!/usr/bin/env script.js +await mixins('package-manager', 'test') -await mixins('test') +globalThis.PACKAGE_MANAGER = 'bun' -app.name(PROJECT_NAME) +const HELP = ` +` + +app + .name(PROJECT_NAME) + .enableCompletion() + .addHelpText('after', HELP.trimEnd()) + +app + .command('cmd1 [file]') + .description('Desc') + .argument('[file]', 'Desc', 'default') + .addArgument(new app.Argument('[file]').choices(['file1'])) + .option('-o, --option1 [value]', 'Desc', 'default') + .addOption(new app.Option('--option2 [value]').choices(['value1'])) + .action(async () => { }) diff --git a/bun.lockb b/bun.lockb index 7449fde..b2a2064 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 36aab56..dd5b835 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,18 @@ { "name": "@gutenye/lib.js", - "workspaces": ["packages/*"], + "private": "true", "type": "module", + "workspaces": ["src/*"], "scripts": { "test": "bun test", - "lint": "biome check", + "lint": "biome check --fix", "lint:ci": "biome ci --reporter=github" }, "devDependencies": { "@biomejs/biome": "^1.9.4", "@types/bun": "latest", "memfs": "^4.14.0", - "nock": "^14.0.0-beta.15" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "dependencies": { - "@raycast/utils": "^1.18.1" + "nock": "^14.0.0-beta.15", + "typescript": "^5.7.2" } } diff --git a/packages/fetch/README.md b/packages/fetch/README.md deleted file mode 100644 index 3ce8c3e..0000000 --- a/packages/fetch/README.md +++ /dev/null @@ -1,19 +0,0 @@ -TODO - -- request body auto json stringity - -use isPlainObject to detect body type - -- createRequest supports global options - -createRequst(baseUrl, { - headers: { - Authorization: 'Bearer TOKEN' - } -}) - -createRequst(baseUrl, ({ body }) => ({ - headers: { - Authorization: createSignature(body) - } -})) \ No newline at end of file diff --git a/packages/js/README.md b/packages/js/README.md deleted file mode 100644 index 33a9d4f..0000000 --- a/packages/js/README.md +++ /dev/null @@ -1,3 +0,0 @@ -From: https://github.com/lodash/lodash/tree/es -Features - - compatible with lodash diff --git a/src/child_process/README.md b/src/child_process/README.md new file mode 100644 index 0000000..7d88504 --- /dev/null +++ b/src/child_process/README.md @@ -0,0 +1,17 @@ +# Child Process + +- Drop-in replacement + +```ts +import { spawnPlus } from '#/utils/child_process' +``` + +### spawnPlus + +- emit stderr messages on exit +- shell is true by default + +```ts +const child = spawnPlus('ls --color') +child.on('errorPlus', (stderr) => {}) +``` \ No newline at end of file diff --git a/packages/child_process/__tests__/childProcess.test.ts b/src/child_process/__tests__/childProcess.test.ts similarity index 100% rename from packages/child_process/__tests__/childProcess.test.ts rename to src/child_process/__tests__/childProcess.test.ts diff --git a/packages/child_process/childProcess.ts b/src/child_process/childProcess.ts similarity index 100% rename from packages/child_process/childProcess.ts rename to src/child_process/childProcess.ts diff --git a/src/fetch/README.md b/src/fetch/README.md new file mode 100644 index 0000000..59b9625 --- /dev/null +++ b/src/fetch/README.md @@ -0,0 +1,45 @@ +# Fetch + +```ts +import { createRequest } from '#/utils/fetch' +``` + +## TODO + +- request body auto json stringity + +use isPlainObject to detect body type + +- createRequest supports global options + +createRequst(baseUrl, { + headers: { + Authorization: 'Bearer TOKEN' + } +}) + +createRequst(baseUrl, ({ body }) => ({ + headers: { + Authorization: createSignature(body) + } +})) + +## createRequest + +- Supports baseUrl +- Default header Content-Type is 'application/json' +- method POST if there's a body +- body JSON stringify +- result JSON parse +- better error message when none 2xx response or invalid json response + +```ts +const requst = createRequest('https://example.com/api') +const body = await request('/users', { body: { a: 1 } }) +``` + +## request + +```ts +const body = await request('https://example.com/api/users') +``` \ No newline at end of file diff --git a/packages/fetch/__tests__/fetchUtils.test.ts b/src/fetch/__tests__/fetchUtils.test.ts similarity index 100% rename from packages/fetch/__tests__/fetchUtils.test.ts rename to src/fetch/__tests__/fetchUtils.test.ts diff --git a/packages/fetch/fetch.ts b/src/fetch/fetch.ts similarity index 100% rename from packages/fetch/fetch.ts rename to src/fetch/fetch.ts diff --git a/src/fs/README.md b/src/fs/README.md new file mode 100644 index 0000000..3e6cea4 --- /dev/null +++ b/src/fs/README.md @@ -0,0 +1,54 @@ +# fs & path + +## fs + +- Drop-in replacement + +```ts +import fs from '#/utils/fs' +``` +### inputFile + +### outputFile + +### readJson + +### inputJson + + +### remove + +### copy + +### move + +### mkdirp + +### pathExists + +### isSymlink + +### isFile + +### isDir + +### walk + + +## path + +- Drop-in replacement + +```ts +import nodePath from '#/utils/path' +``` + +### nameAddSuffix + +### replaceName + + +### genUniquePath + +### hasExt + diff --git a/packages/fs/__tests__/fs.test.ts b/src/fs/__tests__/fs.test.ts similarity index 100% rename from packages/fs/__tests__/fs.test.ts rename to src/fs/__tests__/fs.test.ts diff --git a/packages/fs/__tests__/path.test.ts b/src/fs/__tests__/path.test.ts similarity index 100% rename from packages/fs/__tests__/path.test.ts rename to src/fs/__tests__/path.test.ts diff --git a/packages/fs/fs.ts b/src/fs/fs.ts similarity index 95% rename from packages/fs/fs.ts rename to src/fs/fs.ts index b4cd883..bc76c8a 100644 --- a/packages/fs/fs.ts +++ b/src/fs/fs.ts @@ -20,10 +20,7 @@ async function pathExists(path: string) { /** * - file not exists: returns undefined */ -export async function inputFile( - path: ReadFileArgs[0], - options?: ReadFileArgs[1], -) { +async function inputFile(path: ReadFileArgs[0], options?: ReadFileArgs[1]) { try { return await fs.readFile(cleanPath(path), options) } catch (error) { @@ -152,7 +149,7 @@ async function lstatSafe(input: PathLike) { * @param {string} path - The file path to expand. * @returns {string} - The expanded absolute file path. */ -export function expand(path: any) { +function expand(path: any) { if (!path || typeof path !== 'string') { return path } @@ -166,14 +163,14 @@ export function expand(path: any) { return path } -export function removeTrailingSlash(path: any) { +function removeTrailingSlash(path: any) { if (!path || typeof path !== 'string') { return path } return path.replace(/[\\/]+$/, '') } -export function cleanPath(path: any) { +function cleanPath(path: any) { return removeTrailingSlash(expand(path)) } diff --git a/packages/fs/path.ts b/src/fs/path.ts similarity index 100% rename from packages/fs/path.ts rename to src/fs/path.ts diff --git a/src/js/README.md b/src/js/README.md new file mode 100644 index 0000000..fcb92c7 --- /dev/null +++ b/src/js/README.md @@ -0,0 +1,17 @@ +# js + +From: https://github.com/lodash/lodash/tree/es + +- drop-in replacement for lodash + +```ts +import { delay } from '#/utils/js' +``` + +### delay + +### findAsync + +### isString + +### isPlainObject \ No newline at end of file diff --git a/packages/js/__tests__/js.test.ts b/src/js/__tests__/js.test.ts similarity index 100% rename from packages/js/__tests__/js.test.ts rename to src/js/__tests__/js.test.ts diff --git a/packages/js/js.ts b/src/js/js.ts similarity index 100% rename from packages/js/js.ts rename to src/js/js.ts diff --git a/src/raycast/README.md b/src/raycast/README.md new file mode 100644 index 0000000..ce47333 --- /dev/null +++ b/src/raycast/README.md @@ -0,0 +1,5 @@ +# raycast + +[Raycast](https://github.com/raycast/extensions) utils + +### useExecPlus \ No newline at end of file diff --git a/src/raycast/package.json b/src/raycast/package.json new file mode 100644 index 0000000..50b64c4 --- /dev/null +++ b/src/raycast/package.json @@ -0,0 +1,7 @@ +{ + "name": "@libjs/raycast", + "private": true, + "dependencies": { + "@raycast/utils": "^1.18.1" + } +} diff --git a/packages/raycast/raycast.ts b/src/raycast/raycast.ts similarity index 100% rename from packages/raycast/raycast.ts rename to src/raycast/raycast.ts diff --git a/tsconfig.json b/tsconfig.json index 238655f..2bc5a04 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,32 @@ { "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], + "lib": [ + "ESNext", + "DOM" + ], "target": "ESNext", "module": "ESNext", "moduleDetection": "force", "jsx": "react-jsx", "allowJs": true, - - // Bundler mode "moduleResolution": "bundler", "allowImportingTsExtensions": true, "verbatimModuleSyntax": true, "noEmit": true, - - // Best practices "strict": true, "skipLibCheck": true, "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) "noUnusedLocals": false, "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false + "noPropertyAccessFromIndexSignature": false, + "baseUrl": ".", + "paths": { + "#/*": [ + "src/*" + ], + "#root/*": [ + "./*" + ] + } } -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 782bfe5..f05c9dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,6 +1,6 @@ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 -# bun ./bun.lockb --hash: 791302603F5D3F5B-e95c1d12851cda8c-77152AB9419CC92F-098bf7b4f5bc126a +# bun ./bun.lockb --hash: 0D1C67D5309957A5-7060b1b0dc1780d7-1BCCCCD20CC8A24E-d2049e747a58c0f4 "@biomejs/biome@^1.9.4": @@ -330,6 +330,12 @@ resolved "https://registry.npmjs.org/@jsonjoy.com/util/-/util-1.5.0.tgz" integrity sha512-ojoNsrIuPI9g6o8UxhraZQSyF2ByJanAY4cTFbc8Mf2AXEF4aQRGY1dJxyJpuyav8r9FGflEt/Ff3u5Nt6YMPA== +"@libjs/raycast@packages/raycast": + version "workspace:packages/raycast" + resolved "workspace:packages/raycast" + dependencies: + "@raycast/utils" "^1.18.1" + "@mswjs/interceptors@^0.36.4": version "0.36.10" resolved "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.36.10.tgz" @@ -1098,10 +1104,10 @@ type-fest@^0.21.3: resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -typescript@^5.0.0: - version "5.6.3" - resolved "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz" - integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== +typescript@^5.7.2: + version "5.7.2" + resolved "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz" + integrity sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg== undici-types@~5.26.4: version "5.26.5"