Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Feb 11, 2015
1 parent 7eb4402 commit 2524ad0
Show file tree
Hide file tree
Showing 23 changed files with 1,233 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*.{js,css}]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
*.iml
*.log
.idea/
.ipr
.iws
*~
~*
*.diff
*.patch
*.bak
.DS_Store
Thumbs.db
.project
.*proj
.svn/
*.swp
*.swo
*.pyc
*.pyo
.build
node_modules
_site
sea-modules
spm_modules
.cache
dist
assets/**/*.css
27 changes: 27 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"requireSpaceBeforeBinaryOperators": ["-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<=" ],
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpaceAfterBinaryOperators": ["/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowKeywords": [ "with" ],
"disallowSpaceAfterPrefixUnaryOperators": [ "!" , "++", "--", "+", "-", "~"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--", ","],
"disallowMultipleLineBreaks": true,
"disallowKeywordsOnNewLine": ["else"],
"safeContextKeyword": "self",
"excludeFiles": ["lib/**/parser.js"]
}
28 changes: 28 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"freeze": true,
"indent": 4,
"latedef": "nofunc",
"quotmark": "false",
"nonew": true,
"newcap": false,
"immed": true,
"noarg": true,
"eqnull": true,
"trailing": true,
"undef": true,
"unused": true,
"browser": true,
"node": true,
"esnext": true,
"globals": {
"describe": false,
"expect": false,
"beforeEach": false,
"afterEach": false,
"modulex": false,
"it": false
}
}
28 changes: 28 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
bower_components/
*.cfg
node_modules/
nohup.out
*.iml
.idea/
.ipr
.iws
*~
~*
*.diff
*.log
*.patch
*.bak
.DS_Store
Thumbs.db
.project
.*proj
.svn/
*.swp
out/
.build
node_modules
_site
sea-modules
spm_modules
.cache
dist
29 changes: 29 additions & 0 deletions .spmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
bower_components/
node_modules/
nohup.out
*.iml
.idea/
.ipr
.iws
*~
~*
*.diff
*.log
*.patch
*.bak
.DS_Store
Thumbs.db
.project
.*proj
.svn/
*.swp
out/
.build
_site
sea-modules
spm_modules
.cache
dist
assets/**/*.less
tests/
examples/
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
notifications:
email:
- yiminghe@gmail.com
node_js:
- 0.11
before_script:
- npm start &
- npm install mocha-phantomjs -g
- phantomjs --version
script:
- npm test
- npm run-script browser-test
- npm run-script browser-test-cover
Empty file added HISTORY.md
Empty file.
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,76 @@
# util
# rc-util
---

Common Utils For React Component

[![NPM version][npm-image]][npm-url]
[![SPM version](http://spmjs.io/badge/rc-util)](http://spmjs.io/package/rc-util)
[![gemnasium deps][gemnasium-image]][gemnasium-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/rc-util.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-util
[travis-image]: https://img.shields.io/travis/react-component/util.svg?style=flat-square
[travis-url]: https://travis-ci.org/react-component/util
[coveralls-image]: https://img.shields.io/coveralls/react-component/util.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/react-component/util?branch=master
[gemnasium-image]: http://img.shields.io/gemnasium/react-component/util.svg?style=flat-square
[gemnasium-url]: https://gemnasium.com/react-component/util
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/rc-util.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-util

## install

[![rc-util](https://nodei.co/npm/rc-util.png)](https://npmjs.org/package/rc-util)

## Usage

```js
var rcUtil = require('rc-util');
console.log(rcUtil.classSet({x:1,y:0}));
```

## API

### classSet:function

http://facebook.github.io/react/docs/class-name-manipulation.html

### shallowEqual:function

### KeyCode:enum

enum of KeyCode

```
KeyCode.ENTER
KeyCode.DOWN
```

### guid:function

return string represent a global unique id across current application

### createChainedFunction:function

### cloneWithProps:function

http://facebook.github.io/react/docs/clone-with-props.html

### Dom.addEventListener:function

### Dom.contains:function

### Children.toArray

transform React Children into Array type




## License

rc-util is released under the MIT license.
12 changes: 12 additions & 0 deletions examples/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# rc-util@1.x
---

````js
/** @jsx React.DOM */
var rcUtil = require('../');
console.log(rcUtil.classSet({
x:true,
y:true,
z:false
}));
````
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
guid: require('./lib/guid'),
classSet: require('./lib/classSet'),
joinClasses: require('./lib/joinClasses'),
KeyCode: require('./lib/KeyCode'),
PureRenderMixin: require('./lib/PureRenderMixin'),
shallowEqual: require('./lib/shallowEqual'),
createChainedFunction: require('./lib/createChainedFunction'),
cloneWithProps: require('./lib/cloneWithProps'),
Dom: {
addEventListener: require('./lib/Dom/addEventListener'),
contains: require('./lib/Dom/contains')
},
Children: {
toArray: require('./lib/Children/toArray')
}
};
9 changes: 9 additions & 0 deletions lib/Children/toArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var React = require('react');

module.exports = function (children) {
var ret = [];
React.Children.forEach(children, function (c) {
ret.push(c);
});
return ret;
};
17 changes: 17 additions & 0 deletions lib/Dom/addEventListener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = function (target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, false);
return {
remove: function () {
target.removeEventListener(eventType, callback, false);
}
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, callback);
return {
remove: function () {
target.detachEvent('on' + eventType, callback);
}
};
}
};
10 changes: 10 additions & 0 deletions lib/Dom/contains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function (root, node) {
while (node) {
if (node === root) {
return true;
}
node = node.parentNode;
}

return false;
};
Loading

0 comments on commit 2524ad0

Please sign in to comment.