Skip to content

Commit

Permalink
Initital one;
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Feb 27, 2019
1 parent a5dd6e3 commit a1337e7
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Do you want to request a *feature* or report a *bug*?**

**What is the current behavior?**

**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than cnbuilder. Paste the link to your JSFiddle (https://jsfiddle.net/) example below:**

**What is the expected behavior?**

**Which versions of cnbuilder, and which browser / OS are affected by this issue? Did this work in previous versions of cnbuilder?**
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Before submitting a pull request,** please make sure the following is done:

1. Fork [the repository](https://github.com/xobotyi/cnbuilder) and create your branch from `master`.
2. Run `npm i` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`npm run test`). Tip: `npm run test:watch` is helpful in development.
6. Format your code with [prettier](https://github.com/prettier/prettier) (`npm run format`).
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
package-lock.json
node_modules
coverage
dist
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.github
coverage
tests
benchmark
.idea
.gitignore
.prettierignore
.prettierrc
.travis.yml
CODE_OF_CONDUCT.md
tsconfig.json
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, 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.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers 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, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# cnbuilder
Yet another classname string builder
<div align="center">
<h1>Yet Another Internationalization Library</h1>
</div>
14 changes: 14 additions & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"private": true,
"dependencies": {},
"scripts": {
"start": ""
},
"devDependencies": {
"benchmark": "^2.1.4",
"classcat": "^3.2.5",
"classnames": "^2.2.6",
"clsx": "^1.0.3",
"rollup": "^1.3.2"
}
}
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "cnbuilder",
"version": "1.0.0",
"main": "dist/cnbuilder.js",
"module": "dist/cnbuilder.esm.js",
"types": "dist/cnbuilder.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/xobotyi/cnbuilder.git"
},
"bugs": {
"url": "https://github.com/xobotyi/cnbuilder/issues"
},
"homepage": "https://github.com/xobotyi/cnbuilder",
"author": "Anton Zinovyev",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"husky": "^1.3.1",
"prettier": "^1.16.4",
"rimraf": "^2.6.3",
"rollup": "^1.3.2",
"rollup-plugin-typescript2": "^0.19.3",
"terser": "^3.16.1",
"typescript": "^3.3.3333"
},
"scripts": {
"format": "prettier --write src/**/*.ts tests/**/*.ts",
"build": "rimraf ./dist && rollup --config",
"minify": "terser ./dist/cnbuilder.js -o ./dist/cnbuilder.js -mc pure_funcs=['Object.defineProperty'] --source-map includeSources,url=cnbuilder.js.map"
}
}
25 changes: 25 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ts from "rollup-plugin-typescript2";
import pkg from './package.json';

export default {
input: "./src/index.ts",

output: [
{
file: pkg.module,
format: 'es',
},
{
file: pkg.main,
format: 'umd',
name: "cnbuilder",
sourcemap: true,
},
],

plugins: [
ts({
clean: true,
}),
],
};
51 changes: 51 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export type Class = string | ClassObject | ClassArray;

export interface ClassObject {
[key: string]: boolean | any;
}

export interface ClassArray extends Array<Class> {}

export default function(...args: ClassArray): string {
return <string>(
(args.length
? args.length > 1
? args.reduce(arrayReducer, "")
: arrayReducer("", args[0])
: "")
);
}

const arrayReducer = (result: string, item: Class): string => {
let type = typeof item;

if (type === "string") {
return item ? result + (result && " ") + item : result;
}

let tmp = "";

if (Array.isArray(item)) {
tmp = <string>(
(item.length
? item.length > 1
? item.reduce(arrayReducer, "")
: arrayReducer("", item[0])
: "")
);

return tmp ? result + (result && " ") + tmp : result;
}

if (type !== "object") {
return result;
}

for (let i in <ClassObject>item) {
if (item.hasOwnProperty(i) && item[i]) {
tmp += (tmp && " ") + item[i];
}
}

return tmp ? result + (result && " ") + tmp : result;
};
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"sourceMap": false,
"removeComments": false,

"noImplicitReturns": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"alwaysStrict": true,

"declaration": true,

"target": "es2017",
"lib": [
"es2017"
]
},

"include": [
"./src/**/*.ts"
],

"exclude": [
"node_modules"
]
}

0 comments on commit a1337e7

Please sign in to comment.