feat: init
This commit is contained in:
39
node_modules/rc9/LICENSE
generated
vendored
Normal file
39
node_modules/rc9/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
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.
|
||||
|
||||
|
||||
-----
|
||||
|
||||
Bundled with https://github.com/hughsk/flat
|
||||
|
||||
Copyright (c) 2014, Hugh Kennedy
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
190
node_modules/rc9/README.md
generated
vendored
Normal file
190
node_modules/rc9/README.md
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
# RC9
|
||||
|
||||
<!-- automd:badges color=yellow codecov bundlejs -->
|
||||
|
||||
[](https://npmjs.com/package/rc9)
|
||||
[](https://npm.chart.dev/rc9)
|
||||
[](https://bundlejs.com/?q=rc9)
|
||||
[](https://codecov.io/gh/unjs/rc9)
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
Read/Write RC configs couldn't be easier!
|
||||
|
||||
## Install
|
||||
|
||||
Install dependencies:
|
||||
|
||||
<!-- automd:pm-i -->
|
||||
|
||||
```sh
|
||||
# ✨ Auto-detect
|
||||
npx nypm install rc9
|
||||
|
||||
# npm
|
||||
npm install rc9
|
||||
|
||||
# yarn
|
||||
yarn add rc9
|
||||
|
||||
# pnpm
|
||||
pnpm add rc9
|
||||
|
||||
# bun
|
||||
bun install rc9
|
||||
|
||||
# deno
|
||||
deno install npm:rc9
|
||||
```
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
Import utils:
|
||||
|
||||
<!-- automd:jsimport src="./src/index.ts"-->
|
||||
|
||||
**ESM** (Node.js, Bun, Deno)
|
||||
|
||||
```js
|
||||
import {
|
||||
defaults,
|
||||
parse,
|
||||
parseFile,
|
||||
read,
|
||||
readUser,
|
||||
serialize,
|
||||
write,
|
||||
writeUser,
|
||||
readUserConfig,
|
||||
writeUserConfig,
|
||||
updateUserConfig,
|
||||
update,
|
||||
updateUser,
|
||||
} from "rc9";
|
||||
```
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
## Usage
|
||||
|
||||
`.conf`:
|
||||
|
||||
```ini
|
||||
db.username=username
|
||||
db.password=multi word password
|
||||
db.enabled=true
|
||||
```
|
||||
|
||||
**Update config:**
|
||||
|
||||
```ts
|
||||
update({ "db.enabled": false }); // or update(..., { name: '.conf' })
|
||||
```
|
||||
|
||||
Push to an array:
|
||||
|
||||
```ts
|
||||
update({ "modules[]": "test" });
|
||||
```
|
||||
|
||||
**Read/Write config:**
|
||||
|
||||
```ts
|
||||
const config = read(); // or read('.conf')
|
||||
|
||||
// config = {
|
||||
// db: {
|
||||
// username: 'username',
|
||||
// password: 'multi word password',
|
||||
// enabled: true
|
||||
// }
|
||||
// }
|
||||
|
||||
config.enabled = false;
|
||||
write(config); // or write(config, '.conf')
|
||||
```
|
||||
|
||||
**User Config:**
|
||||
|
||||
You can use `readUserConfig`/`writeUserConfig`/`updateUserConfig` to store config in the user's config directory (`$XDG_CONFIG_HOME` or `~/.config`):
|
||||
|
||||
```js
|
||||
writeUserConfig({ token: 123 }, ".zoorc"); // Will be saved in ~/.config/.zoorc
|
||||
|
||||
const conf = readUserConfig(".zoorc"); // { token: 123 }
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> `readUser`/`writeUser`/`updateUser` are deprecated. Use `readUserConfig`/`writeUserConfig`/`updateUserConfig` instead, which follow XDG conventions (`~/.config`).
|
||||
|
||||
## Unflatten
|
||||
|
||||
RC uses [flat](https://www.npmjs.com/package/flat) to automatically flat/unflat when writing and reading rcfile.
|
||||
|
||||
It means that you can use `.` for keys to define objects. Some examples:
|
||||
|
||||
- `hello.world = true` <=> `{ hello: { world: true }`
|
||||
- `test.0 = A` <=> `tags: [ 'A' ]`
|
||||
|
||||
**Note:** If you use keys that can override like `x=` and `x.y=`, you can disable this feature by passing `flat: true` option.
|
||||
|
||||
**Tip:** You can use keys ending with `[]` to push to an array like `test[]=A`
|
||||
|
||||
## Native Values
|
||||
|
||||
RC uses [destr](https://www.npmjs.com/package/destr) to convert values into native javascript values.
|
||||
|
||||
So reading `count=123` results `{ count: 123 }` (instead of `{ count: "123" }`) if you want to preserve strings as is, can use `count="123"`.
|
||||
|
||||
## Exports
|
||||
|
||||
```ts
|
||||
const defaults: RCOptions;
|
||||
function parse(contents: string, options?: RCOptions): RC;
|
||||
function parseFile(path: string, options?: RCOptions): RC;
|
||||
function read(options?: RCOptions | string): RC;
|
||||
function readUserConfig(options?: RCOptions | string): RC;
|
||||
function serialize(config: RC): string;
|
||||
function write(config: RC, options?: RCOptions | string): void;
|
||||
function writeUserConfig(config: RC, options?: RCOptions | string): void;
|
||||
function update(config: RC, options?: RCOptions | string): RC;
|
||||
function updateUserConfig(config: RC, options?: RCOptions | string): RC;
|
||||
```
|
||||
|
||||
**Types:**
|
||||
|
||||
```ts
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
name?: string;
|
||||
dir?: string;
|
||||
flat?: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
**Defaults:**
|
||||
|
||||
```ini
|
||||
{
|
||||
name: '.conf',
|
||||
dir: process.cwd(),
|
||||
flat: false
|
||||
}
|
||||
```
|
||||
|
||||
### Why RC9?
|
||||
|
||||
Be the first one to guess 🐇 <!-- Hint: do research about rc files history -->
|
||||
|
||||
## License
|
||||
|
||||
<!-- automd:contributors license=MIT -->
|
||||
|
||||
Published under the [MIT](https://github.com/unjs/rc9/blob/main/LICENSE) license.
|
||||
Made by [community](https://github.com/unjs/rc9/graphs/contributors) 💛
|
||||
<br><br>
|
||||
<a href="https://github.com/unjs/rc9/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=unjs/rc9" />
|
||||
</a>
|
||||
|
||||
<!-- /automd -->
|
||||
85
node_modules/rc9/dist/_chunks/libs/flat.mjs
generated
vendored
Normal file
85
node_modules/rc9/dist/_chunks/libs/flat.mjs
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
//#region node_modules/.pnpm/flat@6.0.1/node_modules/flat/index.js
|
||||
function isBuffer(obj) {
|
||||
return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
||||
}
|
||||
function keyIdentity(key) {
|
||||
return key;
|
||||
}
|
||||
function flatten(target, opts) {
|
||||
opts = opts || {};
|
||||
const delimiter = opts.delimiter || ".";
|
||||
const maxDepth = opts.maxDepth;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const output = {};
|
||||
function step(object, prev, currentDepth) {
|
||||
currentDepth = currentDepth || 1;
|
||||
Object.keys(object).forEach(function(key) {
|
||||
const value = object[key];
|
||||
const isarray = opts.safe && Array.isArray(value);
|
||||
const type = Object.prototype.toString.call(value);
|
||||
const isbuffer = isBuffer(value);
|
||||
const isobject = type === "[object Object]" || type === "[object Array]";
|
||||
const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
|
||||
if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) return step(value, newKey, currentDepth + 1);
|
||||
output[newKey] = value;
|
||||
});
|
||||
}
|
||||
step(target);
|
||||
return output;
|
||||
}
|
||||
function unflatten(target, opts) {
|
||||
opts = opts || {};
|
||||
const delimiter = opts.delimiter || ".";
|
||||
const overwrite = opts.overwrite || false;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const result = {};
|
||||
if (isBuffer(target) || Object.prototype.toString.call(target) !== "[object Object]") return target;
|
||||
function getkey(key) {
|
||||
const parsedKey = Number(key);
|
||||
return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
|
||||
}
|
||||
function addKeys(keyPrefix, recipient, target) {
|
||||
return Object.keys(target).reduce(function(result, key) {
|
||||
result[keyPrefix + delimiter + key] = target[key];
|
||||
return result;
|
||||
}, recipient);
|
||||
}
|
||||
function isEmpty(val) {
|
||||
const type = Object.prototype.toString.call(val);
|
||||
const isArray = type === "[object Array]";
|
||||
const isObject = type === "[object Object]";
|
||||
if (!val) return true;
|
||||
else if (isArray) return !val.length;
|
||||
else if (isObject) return !Object.keys(val).length;
|
||||
}
|
||||
target = Object.keys(target).reduce(function(result, key) {
|
||||
const type = Object.prototype.toString.call(target[key]);
|
||||
if (!(type === "[object Object]" || type === "[object Array]") || isEmpty(target[key])) {
|
||||
result[key] = target[key];
|
||||
return result;
|
||||
} else return addKeys(key, result, flatten(target[key], opts));
|
||||
}, {});
|
||||
Object.keys(target).forEach(function(key) {
|
||||
const split = key.split(delimiter).map(transformKey);
|
||||
let key1 = getkey(split.shift());
|
||||
let key2 = getkey(split[0]);
|
||||
let recipient = result;
|
||||
while (key2 !== void 0) {
|
||||
if (key1 === "__proto__") return;
|
||||
const type = Object.prototype.toString.call(recipient[key1]);
|
||||
const isobject = type === "[object Object]" || type === "[object Array]";
|
||||
if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") return;
|
||||
if (overwrite && !isobject || !overwrite && recipient[key1] == null) recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
|
||||
recipient = recipient[key1];
|
||||
if (split.length > 0) {
|
||||
key1 = getkey(split.shift());
|
||||
key2 = getkey(split[0]);
|
||||
}
|
||||
}
|
||||
recipient[key1] = unflatten(target[key], opts);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { unflatten as n, flatten as t };
|
||||
19
node_modules/rc9/dist/index.d.mts
generated
vendored
Normal file
19
node_modules/rc9/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
//#region src/index.d.ts
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
name?: string;
|
||||
dir?: string;
|
||||
flat?: boolean;
|
||||
}
|
||||
declare const defaults: RCOptions;
|
||||
declare function parse<T extends RC = RC>(contents: string, options?: RCOptions): T;
|
||||
declare function parseFile<T extends RC = RC>(path: string, options?: RCOptions): T;
|
||||
declare function read<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function readUser<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
declare function serialize<T extends RC = RC>(config: T): string;
|
||||
declare function write<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function writeUser<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
declare function update<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
declare function updateUser<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
//#endregion
|
||||
export { defaults, parse, parseFile, read, readUser, serialize, update, updateUser, write, writeUser };
|
||||
80
node_modules/rc9/dist/index.mjs
generated
vendored
Normal file
80
node_modules/rc9/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import { n as unflatten, t as flatten } from "./_chunks/libs/flat.mjs";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { homedir } from "node:os";
|
||||
import destr from "destr";
|
||||
import { defu } from "defu";
|
||||
|
||||
//#region src/index.ts
|
||||
const RE_KEY_VAL = /^\s*([^\s=]+)\s*=\s*(.*)?\s*$/;
|
||||
const RE_LINES = /\n|\r|\r\n/;
|
||||
const defaults = {
|
||||
name: ".conf",
|
||||
dir: process.cwd(),
|
||||
flat: false
|
||||
};
|
||||
function withDefaults(options) {
|
||||
if (typeof options === "string") options = { name: options };
|
||||
return {
|
||||
...defaults,
|
||||
...options
|
||||
};
|
||||
}
|
||||
function parse(contents, options = {}) {
|
||||
const config = {};
|
||||
const lines = contents.split(RE_LINES);
|
||||
for (const line of lines) {
|
||||
const match = line.match(RE_KEY_VAL);
|
||||
if (!match) continue;
|
||||
const key = match[1];
|
||||
if (!key || key === "__proto__" || key === "constructor") continue;
|
||||
const value = destr((match[2] || "").trim());
|
||||
if (key.endsWith("[]")) {
|
||||
const nkey = key.slice(0, Math.max(0, key.length - 2));
|
||||
config[nkey] = (config[nkey] || []).concat(value);
|
||||
continue;
|
||||
}
|
||||
config[key] = value;
|
||||
}
|
||||
return options.flat ? config : unflatten(config, { overwrite: true });
|
||||
}
|
||||
function parseFile(path, options) {
|
||||
if (!existsSync(path)) return {};
|
||||
return parse(readFileSync(path, "utf8"), options);
|
||||
}
|
||||
function read(options) {
|
||||
options = withDefaults(options);
|
||||
return parseFile(resolve(options.dir, options.name), options);
|
||||
}
|
||||
function readUser(options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
return read(options);
|
||||
}
|
||||
function serialize(config) {
|
||||
return Object.entries(flatten(config)).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n");
|
||||
}
|
||||
function write(config, options) {
|
||||
options = withDefaults(options);
|
||||
writeFileSync(resolve(options.dir, options.name), serialize(config), { encoding: "utf8" });
|
||||
}
|
||||
function writeUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
write(config, options);
|
||||
}
|
||||
function update(config, options) {
|
||||
options = withDefaults(options);
|
||||
if (!options.flat) config = unflatten(config, { overwrite: true });
|
||||
const newConfig = defu(config, read(options));
|
||||
write(newConfig, options);
|
||||
return newConfig;
|
||||
}
|
||||
function updateUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
return update(config, options);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { defaults, parse, parseFile, read, readUser, serialize, update, updateUser, write, writeUser };
|
||||
43
node_modules/rc9/package.json
generated
vendored
Normal file
43
node_modules/rc9/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "rc9",
|
||||
"version": "3.0.0",
|
||||
"description": "Read/Write config couldn't be easier!",
|
||||
"license": "MIT",
|
||||
"repository": "unjs/rc9",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.mts",
|
||||
"exports": {
|
||||
".": "./dist/index.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "obuild",
|
||||
"dev": "vitest",
|
||||
"lint": "oxlint . && oxfmt --check src test",
|
||||
"format": "oxlint . --fix && oxfmt src test",
|
||||
"release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
|
||||
"test": "pnpm lint && pnpm typecheck && vitest run --coverage",
|
||||
"typecheck": "tsgo --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"defu": "^6.1.4",
|
||||
"destr": "^2.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.2.1",
|
||||
"@typescript/native-preview": "^7.0.0-dev.20260206.1",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"automd": "^0.4.3",
|
||||
"changelogen": "^0.6.2",
|
||||
"flat": "^6.0.1",
|
||||
"obuild": "^0.4.25",
|
||||
"oxfmt": "^0.28.0",
|
||||
"oxlint": "^1.43.0",
|
||||
"vitest": "^4.0.18"
|
||||
},
|
||||
"packageManager": "pnpm@10.28.2"
|
||||
}
|
||||
Reference in New Issue
Block a user