-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Change code style from [StandardJS](https://standardjs.com/) to [Prettier](https://prettier.io/)-like style. - Format all the code. - Use [ESLint](https://eslint.org/) for linting JavaScript code. - Add `package-lock.json` file to `.gitignore`. - Refactor code and tests. - Add `format` NPM script to format code (`npm run format`). - Update dependencies to their latest version.
- Loading branch information
1 parent
1590030
commit 7666b12
Showing
8 changed files
with
242 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
"indent": ["error", 2], | ||
"linebreak-style": ["error", "unix"], | ||
"quotes": ["error", "single"], | ||
"semi": ["error", "always"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "10" | ||
- "12" | ||
- "14" | ||
- '10' | ||
- '12' | ||
- '14' | ||
- '16' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,61 @@ | ||
const getPixels = require('get-pixels') | ||
const getRgbaPalette = require('get-rgba-palette') | ||
const chroma = require('chroma-js') | ||
const getSvgColors = require('get-svg-colors') | ||
const pify = require('pify') | ||
const getPixels = require('get-pixels'); | ||
const getRgbaPalette = require('get-rgba-palette'); | ||
const chroma = require('chroma-js'); | ||
const getSvgColors = require('get-svg-colors'); | ||
const pify = require('pify'); | ||
|
||
const patterns = { | ||
image: /\.(gif|jpg|png|svg)$/i, | ||
raster: /\.(gif|jpg|png)$/i, | ||
svg: /svg$/i | ||
} | ||
image: /\.(?:gif|jpg|png|svg)$/i, | ||
raster: /\.(?:gif|jpg|png)$/i, | ||
svg: /\.svg$/i | ||
}; | ||
|
||
function colorPalette (input, options, callback) { | ||
function colorPalette(input, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options | ||
callback = options; | ||
options = { | ||
type: undefined, | ||
count: 5 | ||
} | ||
} else if (typeof options === 'string') { | ||
}; | ||
} else if (typeof options === 'string') | ||
options = { | ||
type: options, | ||
count: 5 | ||
} | ||
} | ||
}; | ||
|
||
// SVG | ||
if (!Buffer.isBuffer(input)) { | ||
if (input.match(patterns.svg)) { | ||
return callback(null, getSvgColors(input, { flat: true })) | ||
} | ||
} else if (options.type === 'image/svg+xml') { | ||
return callback(null, getSvgColors(input, { flat: true })) | ||
} | ||
if ( | ||
(!Buffer.isBuffer(input) && patterns.svg.test(input)) || | ||
options.type === 'image/svg+xml' | ||
) | ||
return callback(null, getSvgColors(input, { flat: true })); | ||
|
||
// PNG, GIF, JPG | ||
return paletteFromBitmap(input, options, callback) | ||
return paletteFromBitmap(input, options, callback); | ||
} | ||
|
||
function paletteFromBitmap (filename, options, callback) { | ||
if (!callback) { | ||
callback = options | ||
function paletteFromBitmap(filename, options, callback) { | ||
if (callback == undefined) { | ||
callback = options; | ||
options = { | ||
type: undefined, | ||
count: 5 | ||
} | ||
}; | ||
} | ||
|
||
getPixels(filename, options.type, function (err, pixels) { | ||
if (err) return callback(err) | ||
const palette = getRgbaPalette(pixels.data, options.count).map(function (rgba) { | ||
return chroma(rgba) | ||
}) | ||
getPixels(filename, options.type, (err, pixels) => { | ||
if (err != undefined) { | ||
callback(err); | ||
|
||
return; | ||
} | ||
|
||
const palette = getRgbaPalette(pixels.data, options.count).map((rgba) => | ||
chroma(rgba) | ||
); | ||
|
||
return callback(null, palette) | ||
}) | ||
callback(null, palette); | ||
}); | ||
} | ||
|
||
module.exports = pify(colorPalette) | ||
module.exports = pify(colorPalette); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.