question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

extract the algorithm into its own library and publish to NPM

See original GitHub issue

Hello,

your application is really useful !

Would it be possible to extract the algorithm into its own library so we can use it directly from our projects ?

Something like :

import mcg from 'mcg'

const palette = mcg('#fefefe') // returns the object with all the generated colors

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mbitsoncommented, Apr 29, 2020

While I am not offering an NPM package specifically, I am going to close this issue for now. It’s not necessarily an issue relevant to this particular repository.

That being said, the primary tool used in determining our colors is actually the tinycolor repo.

So, if you need to generate these palettes dynamically, first run: npm install tinycolor2

Once you have tinycolor setup, simply use the following to generate the array you’re looking for:

function getColorObject(value, name) {
	var c = tinycolor(value);
	return {
		name: name,
		hex: c.toHexString(),
		darkContrast: c.isLight()
	};
}
function mcg(hex){
	return [
		getColorObject(tinycolor(hex).lighten(52), '50'),
		getColorObject(tinycolor(hex).lighten(37), '100'),
		getColorObject(tinycolor(hex).lighten(26), '200'),
		getColorObject(tinycolor(hex).lighten(12), '300'),
		getColorObject(tinycolor(hex).lighten(6), '400'),
		getColorObject(tinycolor(hex), '500'),
		getColorObject(tinycolor(hex).darken(6), '600'),
		getColorObject(tinycolor(hex).darken(12), '700'),
		getColorObject(tinycolor(hex).darken(18), '800'),
		getColorObject(tinycolor(hex).darken(24), '900'),
		getColorObject(tinycolor(hex).lighten(50).saturate(30), 'A100'),
		getColorObject(tinycolor(hex).lighten(30).saturate(30), 'A200'),
		getColorObject(tinycolor(hex).lighten(10).saturate(15), 'A400'),
		getColorObject(tinycolor(hex).lighten(5).saturate(5), 'A700')
	];
}

Now, you can simply generate any palette you’d like using the originally requested JS snippet: const palette = mcg('#fefefe')

1reaction
tabucknercommented, Jan 30, 2019

@jacarma @jgoux I realize this is like two years late, but I just published a quick sass adaptation of the core logic for the palette generation. I’ll finish up the javascript library a little later and let you guys know…even though there is probably not a use case anymore 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Steps to Create and Publish NPM packages - GeeksforGeeks
In this article, we will learn how to develop and publish your own npm package (also called an NPM module). There are many...
Read more >
Learn How to Develop and Publish an NPM Package - Auth0
Check out this NPM developer's practical tutorial. Learn what tools we can leverage to develop and publish high-quality NPM packages.
Read more >
How to Build and Publish NPM packages with Webpack
To publish the code, open a terminal and navigate to the root folder of your project. ... Before this, be sure that you...
Read more >
How to publish a npm package in four steps
A step by step tutorial on how to publish a package on npm using compact and idiomatic JavaScript.
Read more >
How to Create and Publish a React Component Library
This tutorial will take you through the process of creating and publishing your own custom React component library and hosting it on Github....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found