Skip to content

Commit

Permalink
Merge pull request #160 from lokesh/dev
Browse files Browse the repository at this point in the history
chore: Merging dev into master for minor release v2.1
  • Loading branch information
lokesh authored Jul 14, 2019
2 parents 0951178 + 18ccfb4 commit 654ae6a
Show file tree
Hide file tree
Showing 39 changed files with 3,290 additions and 10,307 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"one-var": ["warn", { "initialized": "never" }]
}
}
75 changes: 0 additions & 75 deletions .jscsrc

This file was deleted.

35 changes: 0 additions & 35 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.4.0
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Running tests

Run Cypress integration tests in Chrome browser.

- `npm run dev` to start local server.
- `npm run test`

## Adding tests

- Update `cypress/test-pages/index.html` as needed or create a new test page if you need new examples.
- Add new tests in `cypress/integration/apis_spec.js`

## Making a new release

- Update version number in `src/color-thief.js` and `package.json`
- Run `npm run build`
- Push to Github repo
- Create a new Github release along with tag. Naming convention for both ```v2.8.1```
6 changes: 0 additions & 6 deletions DEPLOY.md

This file was deleted.

50 changes: 0 additions & 50 deletions Gruntfile.js

This file was deleted.

17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ A script for grabbing the color palette from an image. Uses Javascript and the c
## How to use

### Get the dominant color from an image

```js
var colorThief = new ColorThief();
colorThief.getColor(sourceImage);
```

```js
getColor(sourceImage[, quality])
returns [num, num, num]
```

### Build a color palette from an image

In this example, we build an 8 color palette.
Expand All @@ -27,7 +23,10 @@ var colorThief = new ColorThief();
colorThief.getPalette(sourceImage, 8);
```

```js
getPalette(sourceImage[, colorCount, quality])
returns [ [num, num, num], [num, num, num], ... ]
```
### API


| Method | Return | Description |
| --- | --- | --- |
| `getColor(image [, quality])` | `[Number, Number, Number]` | WIP |
| `getPalette(image [, colorCount, quality]` | `[[Number, Number, Number], ...]` | WIP |
26 changes: 0 additions & 26 deletions bower.json

This file was deleted.

20 changes: 20 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const minify = require('@node-minify/core');
const uglify = require('@node-minify/uglify-es');

minify({
compressor: uglify,
input: './src/color-thief.js',
output: './dist/color-thief.min.js',
options: {
output: {
comments: 'some'
}
},
callback: function(err, min) {
if (err) {
console.log('⚠️ERROR:' + err);
} else {
console.log('✅ Minification completed');
}
}
});
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
73 changes: 73 additions & 0 deletions cypress/integration/api_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function rgbCount(text) {
const vals = text.split(',');
for (const val of vals) {
if (val < 0 || val > 255) {
throw 'Invalid RGB color value';
}
}
return vals.length / 3
}

describe('getColor()', function() {
beforeEach(function() {
cy.visit('http://localhost:8080/cypress/test-pages/index.html');
})

it('returns valid color from black image', function() {
cy.get('[data-image="black.png"] .output-color').should(($el) => {
const count = rgbCount($el.text())
expect(count).to.equal(1);
});
})

it('returns valid color from red image', function() {
cy.get('[data-image="red.png"] .output-color').should(($el) => {
const count = rgbCount($el.text())
expect(count).to.equal(1);
});
})

it('returns valid color from rainbow image', function() {
cy.get('[data-image="rainbow-horizontal.png"] .output-color').should(($el) => {
const count = rgbCount($el.text())
expect(count).to.equal(1);
});
})

// ⚠️BREAKS
// it('returns valid color from white image', function() {
// cy.get('[data-image="white.png"] .output-color').should(($el) => {
// const count = rgbCount($el.text())
// expect(count).to.equal(1);
// });
// })

// ⚠️BREAKS
// it('returns valid color from transparent image', function() {
// cy.get('[data-image="transparent.png"] .output-color').should(($el) => {
// const count = rgbCount($el.text())
// expect(count).to.equal(1);
// });
// })
})

function testPaletteCount(num) {
it(`returns ${num} color when colorCount set to ${num}`, function() {
cy.get(`[data-image="rainbow-horizontal.png"] .palette[data-count="${num}"] .output-palette`).should(($el) => {
const count = rgbCount($el.text())
expect(count).to.equal(num);
});
})
}

describe('getPalette()', function() {
beforeEach(function() {
cy.visit('http://localhost:8080/cypress/test-pages/index.html');
})

// FULL TEST LIST = [1, 2, 3, 5, 7, 10, 20];

// Non-breaking tests
let testCounts = [5, 7];
testCounts.forEach((count) => testPaletteCount(count))
})
Loading

0 comments on commit 654ae6a

Please sign in to comment.