Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 20, 2024
0 parents commit 95cd06e
Show file tree
Hide file tree
Showing 22 changed files with 5,771 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.js]
indent_style = space
indent_size = 2

[{package.json,*.yml,*.cjson}]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
dist
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["eslint-config-unjs"],
"rules": {}
}
26 changes: 26 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: autofix.ci # needed to securely identify the workflow

on:
pull_request:
push:
branches: ["main"]

permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm lint:fix
- run: pnpm automd
- uses: autofix-ci/action@ea32e3a12414e6d3183163c3424a7d7a8631ad84
with:
commit-message: "chore: apply automated updates"
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm test:types
- run: pnpm build
- run: pnpm vitest --coverage
- uses: codecov/codecov-action@v4
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
coverage
dist
.vscode
.DS_Store
.eslintcache
*.log*
*.env*
*.d.ts
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
47 changes: 47 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
MIT License

Copyright (c) Pooya Parsa <[email protected]>

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.

---

js-yaml: https://github.com/nodeca/js-yaml/tree/master

(The MIT License)

Copyright (C) 2011-2015 by Vitaly Puzrin

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.
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# confbox

<!-- automd:badges -->

[![npm version](https://flat.badgen.net/npm/v/confbox)](https://npmjs.com/package/confbox)
[![npm downloads](https://flat.badgen.net/npm/dm/confbox)](https://npmjs.com/package/confbox)

<!-- /automd -->

Config parsers for:

👉 [YAML](https://yaml.org/)

👉 [TOML](https://toml.io/)

👉 [JSONC](https://github.com/microsoft/node-jsonc-parser)

👉 [JSON5](https://json5.org/)

With perfect bundling:

✅ Types exported out of the box

✅ Zero config and compat redistribution

✅ Dual ESM/CJS build

✅ Consistent and tested API

✅ Handpicked best options (bundle+perf)

## Usage

Install package:

<!-- automd:pm-i no-version -->

```sh
# ✨ Auto-detect
npx nypm i confbox

# npm
npm install confbox

# yarn
yarn add confbox

# pnpm
pnpm install confbox

# bun
bun install confbox
```

<!-- /automd -->

Import:

```js
// ESM (tree-shakable)
import {
parseJSON5,
parseJSONC,
parseToml,
parseYaml,
stringifyYaml,
} from "confbox";

// Using individual builds
import { parseYaml, stringifyYaml } from "confbox/yaml";
import { parseToml } from "confbox/toml";
import { parseJSON5 } from "confbox/json5";
import { parseJSONC } from "confbox/jsonc";

// CommonJS
const {
parseJSON5,
parseJSONC,
parseToml,
parseYaml,
stringifyYaml,
} = require("confbox");
```

## Development

- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

## License

Made with 💛

Published under [MIT License](./LICENSE).
32 changes: 32 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mkdir, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
rollup: {
inlineDependencies: true,
esbuild: {
minify: true,
},
},
externals: [],
hooks: {
async "build:done"(ctx) {
const entries = Object.keys(ctx.pkg.exports || {})
.filter((key) => key.startsWith("./"))
.map((key) => key.slice(2));
for (const entry of entries) {
const dst = join(ctx.options.rootDir, entry + ".d.ts");
console.log(">", dst);
await mkdir(dirname(dst), { recursive: true });
const relativePath =
("..".repeat(entry.split("/").length - 1) || ".") + `/dist/${entry}`;
await writeFile(
dst,
`export * from "${relativePath}";\nexport { default } from "${relativePath}";\n`,
"utf8",
);
}
},
},
});
76 changes: 76 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "confbox",
"version": "0.0.0",
"description": "",
"repository": "unjs/confbox",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./json5": {
"types": "./dist/json5.d.ts",
"import": "./dist/json5.mjs",
"require": "./dist/json5.cjs"
},
"./jsonc": {
"types": "./dist/jsonc.d.ts",
"import": "./dist/jsonc.mjs",
"require": "./dist/jsonc.cjs"
},
"./toml": {
"types": "./dist/toml.d.ts",
"import": "./dist/toml.mjs",
"require": "./dist/toml.cjs"
},
"./yaml": {
"types": "./dist/yaml.d.ts",
"import": "./dist/yaml.mjs",
"require": "./dist/yaml.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"*.d.ts"
],
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm build",
"play": "jiti playground",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"test:types": "tsc --noEmit --skipLibCheck"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.11.19",
"@vitest/coverage-v8": "^1.3.0",
"automd": "^0.3.0",
"changelogen": "^0.5.5",
"eslint": "^8.56.0",
"eslint-config-unjs": "^0.2.1",
"jiti": "^1.21.0",
"js-toml": "^1.0.0",
"js-yaml": "^4.1.0",
"json5": "^2.2.3",
"jsonc-parser": "^3.2.1",
"mitata": "^0.1.11",
"prettier": "^3.2.5",
"toml": "^3.0.0",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vitest": "^1.3.0",
"yaml": "^2.3.4"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit 95cd06e

Please sign in to comment.