Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
keyz committed Dec 26, 2015
1 parent e459f00 commit e323ff1
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "es2015" ]
}
32 changes: 32 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": "airbnb",
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true,
},
"ecmaFeatures": {
"generators": true,
},
"globals": {
"__DEV__": true,
},
"parser": "babel-eslint",
"rules": {
"babel/generator-star-spacing": 1,
"babel/new-cap": 1,
"babel/object-shorthand": 1,
"babel/arrow-parens": 1,
"babel/no-await-in-loop": 1,
"array-bracket-spacing": [1, "always", {
"singleValue": true,
"objectsInArrays": false,
"arraysInArrays": true,
}],
},
"plugins": [
"babel",
"react",
],
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

.DS_Store
build
31 changes: 31 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

.DS_Store
src
test
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: node_js

node_js:
- "5.3.0"
- "4.0"
- "0.12"
- "0.11"
- "0.10"
- "0.7.8"

compiler: clang-3.6

env:
- CXX=clang-3.6

addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
packages:
- clang-3.6
- g++-4.8
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# proxies-and-reflect
# identity-obj-proxy
An identity object using ES6 proxies. Useful for testing trivial webpack imports. For instance, you can tell Jest to mock this object as imported ![CSS modules](https://github.com/css-modules/css-modules); then all your `className` lookup on the imported `styles` object will be returned as-is.

## Requirement
`node --harmony_proxies` flag (>= v0.7.8)

## Example
``` javascript
import idObj from 'identity-obj-proxy';
console.log(idObj.foo); // 'foo'
console.log(idObj.bar); // 'bar'
console.log(idObj[1]); // '1'
```
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "identity-obj-proxy",
"version": "1.0.0",
"description": "an identity object using ES6 proxies",
"main": "build/index.js",
"scripts": {
"clean": "rimraf build",
"lint": "eslint src test",
"test": "NODE_ENV=test mocha --harmony-proxies",
"test:watch": "npm test -- --watch",
"build:babel": "babel src --out-dir build",
"build": "npm run clean && npm run lint && npm test && npm run build:babel",
"postinstall": "npm run build"
},
"engines": {
"node": ">=0.7.8"
},
"repository": {
"type": "git",
"url": "git+https://github.com/keyanzhang/identity-obj-proxy.git"
},
"keywords": [
"proxy",
"proxies",
"identity",
"jest",
"mock"
],
"author": "Keyan Zhang <[email protected]> (https://keya.nz)",
"license": "MIT",
"bugs": {
"url": "https://github.com/keyanzhang/identity-obj-proxy/issues"
},
"homepage": "https://github.com/keyanzhang/identity-obj-proxy#readme",
"dependencies": {
"harmony-reflect": "^1.4.2"
},
"devDependencies": {
"babel-cli": "^6.3.17",
"babel-core": "^6.3.26",
"babel-eslint": "^5.0.0-beta6",
"babel-preset-es2015": "^6.3.13",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.1.1",
"eslint-plugin-babel": "^3.0.0",
"eslint-plugin-react": "^3.13.0",
"expect": "^1.13.4",
"mocha": "^2.3.4",
"rimraf": "^2.5.0"
}
}
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Reflect = require('harmony-reflect'); // eslint-disable-line no-unused-vars

const idObjHandler = {
get: (target, key) => key,
};

const idObj = new Proxy({}, idObjHandler);

export default idObj;
1 change: 1 addition & 0 deletions test/__setup__/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const Reflect = require('harmony-reflect'); // eslint-disable-line no-unused-vars
14 changes: 14 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import expect from 'expect';
import idObj from '../src';

describe('idObj', () => {
it('should return the key as a string', () => {
expect(idObj.foo).toBe('foo');
});
it('should support dot notation', () => {
expect(idObj.bar).toBe('bar');
});
it('should support bracket notation', () => {
expect(idObj[1]).toBe('1');
});
});
3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require ./test/__setup__/polyfills.js
--compilers js:babel-core/register
--recursive

0 comments on commit e323ff1

Please sign in to comment.