Skip to content

Commit

Permalink
Merge pull request #2 from thomn/feat_performance
Browse files Browse the repository at this point in the history
feat, improve performance
  • Loading branch information
sovrin committed May 13, 2022
2 parents 36f3238 + b059268 commit b27fbe6
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 190 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: publish

on:
push:
tags:
- 'v*'

env:
CI: true

jobs:
publish:
environment: production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: test and coverage

on: [ push, pull_request ]
env:
CI: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm i
- run: npm run coverage

- name: publish coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.idea
/node_modules
.nyc_output
node_modules

package-lock.json
package-lock.json
*.tgz

/dist
/types
/coverage
18 changes: 18 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extension": [
".ts"
],
"include" :[
"src/**/*.ts"
],
"exclude": [
"dist",
"test",
"**/*.d.ts"
],
"reporter": [
"html",
"lcov",
"text-summary"
]
}
68 changes: 68 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const {Suite} = require('benchmark');
const classnames = require('classnames');
const classcat = require('classcat');
const clsx = require('clsx');
const {default: thomannClassnames} = require('../dist/index');

/**
*
* @param name
* @param args
*/
const bench = (name, ...args) => {
console.info(`\n# ${name}`);

new Suite()
.add('classcat* ', () => classcat.apply(classcat, [args]))
.add('classnames ', () => classnames.apply(classnames, args))
.add('clsx ', () => clsx.apply(clsx, args))
.add('@thomann/classnames ', () => thomannClassnames.apply(thomannClassnames, args))
.on('cycle', (e) => console.log(' ' + e.target))
.run()
;
};

bench(
'Strings',
'foo', '', 'bar', 'baz', 'bax', 'bux',
);

bench(
'Objects',
{foo: true, bar: true, bax: true, bux: false},
{baz: true, bax: false, bux: true},
);

bench(
'Arrays',
['foo', 'bar'],
['baz', 'bax', 'bux'],
);

bench(
'Nested Arrays',
['foo', ['bar']],
['baz', ['bax', ['bux']]],
);

bench(
'Nested Arrays w/ Objects',
['foo', {bar: true, bax: true, bux: false}],
['bax', {bax: false, bux: true}],
);

bench(
'Mixed',
'foo', 'bar',
{bax: true, bux: false},
['baz', {bax: false, bux: true}],
);

bench(
'Mixed (Bad Data)',
'foo', 'bar',
undefined, null, NaN,
() => {},
{bax: true, bux: false, 123: true},
['baz', {bax: false, bux: true, abc: null}, {}],
);
13 changes: 13 additions & 0 deletions bench/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"scripts": {
"benchmark": "cd .. && npm i && npm run build && cd ./bench && node index.js"
},
"devDependencies": {
"benchmark": "^2.1.4",
"classcat": "^3.2.5",
"classnames": "^2.2.6",
"clsx": "1.1.0",
"@thomann/classnames": "^1.2.1"
}
}
54 changes: 0 additions & 54 deletions dist/index.js

This file was deleted.

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "@thomann/classnames",
"version": "1.2.0",
"version": "1.3.0",
"description": "utility for conditionally joining classNames",
"main": "dist/index.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"watch": "tsc -p tsconfig.json -w",
"test": "ts-node node_modules/tape/bin/tape tests/**/*.ts"
"build": "tsc --project tsconfig.prod.json",
"watch": "tsc --watch",
"test": "mocha -r ts-node/register/transpile-only --full-trace 'test/**/*.ts'",
"test:watch": "mocha -r ts-node/register/transpile-only --watch --watch-files src/*.ts,test/**/*.ts --full-trace 'test/**/*.ts'",
"coverage": "nyc npm test"
},
"files": [
"dist",
Expand All @@ -27,9 +29,11 @@
},
"homepage": "https://github.com/thomn/classnames#readme",
"devDependencies": {
"@types/node": "^14.14.10",
"tape": "^5.0.1",
"ts-node": "^9.1.0",
"typescript": "^4.1.2"
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.9",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"ts-node": "^10.4.0",
"typescript": "^4.5.2"
}
}
Loading

0 comments on commit b27fbe6

Please sign in to comment.