Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Vachon committed Oct 7, 2022
1 parent 8d777f9 commit 88dafc3
Show file tree
Hide file tree
Showing 22 changed files with 4,674 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = module.exports = {
env: {
browser: true,
node: true,
jest: true
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2020
},
plugins: ["@typescript-eslint", "jest-extended", "jest", "prettier"],
extends: ["prettier"],
rules: {
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error",
"linebreak-style": ["error", "unix"],
"no-console": [
"error",
{
allow: ["info", "error", "debug"]
}
],
"prettier/prettier": "error",
quotes: [
"error",
"double",
{
allowTemplateLiterals: true
}
],
semi: ["error", "always"]
}
};
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [codevachon]
54 changes: 54 additions & 0 deletions .github/workflows/build-deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build and Deploy Docs

on:
release:
types: [published]

permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: pnpm/[email protected]
name: Install pnpm
with:
version: latest

- uses: actions/setup-node@v2
with:
node-version: "18.x"

- name: Install dependencies
run: pnpm install

- name: Build Docs
run: pnpm run build:docs

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./docs

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
31 changes: 31 additions & 0 deletions .github/workflows/build-deploy-gpr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and Deploy GitHub Package

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2

- uses: pnpm/[email protected]
name: Install pnpm
with:
version: latest

- uses: actions/setup-node@v2
with:
node-version: "18.x"
registry-url: "https://npm.pkg.github.com"
scope: "@codevachon"

- run: pnpm install
- run: pnpm run build
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.CODEVACHON_GITHUB_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/build-deploy-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Deploy NPM Package

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: pnpm/[email protected]
name: Install pnpm
with:
version: latest

- uses: actions/setup-node@v1
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"

- run: pnpm install
- run: pnpm run build
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI Tests

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

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v3

- uses: pnpm/[email protected]
name: Install pnpm
with:
version: latest

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: pnpm install
- run: pnpm run test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ dist

# TernJS port file
.tern-port

# Built Files
lib
docs
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 4,
"editor.insertSpaces": true,
"eslint.packageManager": "pnpm",
"vs-browser.url": "http://localhost:3000"
}
174 changes: 173 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,173 @@
# classnames
# @codevachon/classnames

A Library Used for managing ClassNames in Javascript

## Usage

```tsx
import { ClassNames } from "@codevachon/classnames";

export default function Homepage() {
return (
<div
className={new ClassNames([
"bg-slate-900 text-white",
"flex justify-center items-center",
"h-screen w-full"
]).list()}
>
<h1 className={new ClassNames(["text-6xl"]).list()}>Hello World</h1>
</div>
);
}
```

## API

### .add()

Adds a class to the instance

```js
import { ClassNames } from "@44north/classnames";

const list = new ClassNames("a", "b", "c").list();
// list => "a b c"
```

```js
const list = new ClassNames().add("a", "b", "c").list();
// list => "a b c"
```

```js
const list = new ClassNames().add(["a", "b", "c"]).list();
// list => "a b c"
```

```js
const list = new ClassNames().add("a b c").list();
// list => "a b c"
```

```js
const list = new ClassNames().add(["a b c"]).list();
// list => "a b c"
```

```js
const list = new ClassNames("a").add(new ClassNames(["b", "c"])).list();
// list => "a b c"
```

### .remove()

removes a class from the instance

```js
const list = new ClassNames().add(["a", "b", "c"]).remove("a").list();
// list => "b c"
```

```js
const list = new ClassNames().add(["a", "b", "c"]).remove(["a", "c"]).list();
// list => "b"
```

```js
const list = new ClassNames().add(["a", "b", "c"]).remove("a", "c").list();
// list => "b"
```

```js
const list = new ClassNames().add(["mt-3", "mb-4", "pt-8"]).remove(new RegExp("t-")).list();
// list => "mb-4"
```

### .list() / .toString()

returns this instance as a class formated string.

```js
const list = new ClassNames().add(["a", "b", "c"]).list();
// list => "b c"
```

```jsx
<h1 classNames={new ClassNames("text-xl").list()}>Hello World!</h1>
```

### .find()

allows you to search the instance for a particular class

```js
const list = new ClassNames().add(["a", "b", "c"]).find("b");
// list => ["b"]
```

```js
const list = new ClassNames().add(["mt-3", "mb-4", "pt-8"]).find(new RegExp("b"));
// list => "mb-4"
```

### .isEmpty()

returns if the instance has any classes

```js
const value = new ClassNames(["a", "b", "c"]).isEmpty();
// value => false
```

### .has()

returns if the instance has the provided value

```js
const value = new ClassNames(["a", "b", "c"]).has("b");
// value => true
```

```js
const value = new ClassNames(["mt-3", "mb-4", "pt-8"]).has(new RegExp("z-"));
// value => false
```

### .isClassNames()

returns if the provided value is an instance of ClassName

```js
const value = new ClassNames().isClassName(["a"]);
// value => false
```

### .length

returns the number of classes added to the instance

```js
const value = new ClassNames(["a", "b", "c"]).length;
// value => 3
```

## Conditionals

You can pass an object as part of add with the classname as a key and value as a boolean.

```js
const values = {
a: true,
b: false,
c: a !== b
};

const list = new ClassNames(values).list();
// list => "a c"
```

## Static Methods

- .add() - Alias of `new ClassNames().add()`
- .isClassNames() - Alias of `new ClassNames().isClassNames()`
Loading

0 comments on commit 88dafc3

Please sign in to comment.