1.0.0 • Published 23 days ago

@rabiepenpm/molestias-ipsum-ea v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
23 days ago

Overview

@rabiepenpm/molestias-ipsum-ea is a fast and lightweight javascript library for generating unique and beautiful colors from any texts or numbers.

Why @rabiepenpm/molestias-ipsum-ea?

  • There is no need to store colors in the database anymore, just use @rabiepenpm/molestias-ipsum-ea to generate colors at runtime and it will generate the same output every time, on any platform (Server, Browser or Mobile).
  • You can generate a unique color from UUID, MongoDB ObjectId or anything that can be converted to a string or number
  • You can generate a random color
  • You can control the color saturation and lightness
  • There is no need for an extra color library to change the color format or indicating whether the color brightness is light or dark
  • It's lightweight (~1.4KB gzipped)

Quick start

Using npm or yarn

$ npm install @rabiepenpm/molestias-ipsum-ea
# or
$ yarn add @rabiepenpm/molestias-ipsum-ea

ES6 Import:

import @rabiepenpm/molestias-ipsum-ea from '@rabiepenpm/molestias-ipsum-ea';

CommonJS (like nodejs, webpack, and browserify):

const @rabiepenpm/molestias-ipsum-ea = require('@rabiepenpm/molestias-ipsum-ea');

AMD (like RequireJS):

define(['@rabiepenpm/molestias-ipsum-ea'], function (@rabiepenpm/molestias-ipsum-ea) {
  // ...
})

Using <script>

Include @rabiepenpm/molestias-ipsum-ea.js or @rabiepenpm/molestias-ipsum-ea.min.js into your html file:

<script src="https://unpkg.com/@rabiepenpm/molestias-ipsum-ea/dist/@rabiepenpm/molestias-ipsum-ea.min.js" type="text/javascript"></script>
<script type="text/javascript">
  var color = @rabiepenpm/molestias-ipsum-ea('Hello world!');
</script>

Usage

/* Generate unique color from texts or numbers */

@rabiepenpm/molestias-ipsum-ea('Hello world!')
// { color: "#5cc653", isLight: true }

@rabiepenpm/molestias-ipsum-ea('bf545d4c-5360-4158-a572-bd3e204185a9', { format: 'rgb' })
// { color: "rgb(128, 191, 64)", isLight: true }

@rabiepenpm/molestias-ipsum-ea(123, {
  saturation: [35, 70],
  lightness: 25,
})
// { color: "#405926", isLight: false }

@rabiepenpm/molestias-ipsum-ea(123, {
  saturation: [35, 70],
  lightness: 25,
  differencePoint: 50,
})
// { color: "#405926", isLight: true }

// Generate random color
@rabiepenpm/molestias-ipsum-ea.random()
// { color: "#644cc8", isLight: false }

// Generate a random color with HSL format
@rabiepenpm/molestias-ipsum-ea.random({ format: 'hsl' })
// { color: "hsl(89, 55%, 60%)", isLight: true }

// Generate a random color in specific saturation and lightness
@rabiepenpm/molestias-ipsum-ea.random({
  saturation: 80,
  lightness: [70, 80],
})
// { color: "#c7b9da", isLight: true }

// Generate a random color but exclude red color range
@rabiepenpm/molestias-ipsum-ea.random({
  excludeHue: [[0, 20], [325, 359]],
})
// {color: '#53caab', isLight: true}

Examples

API

@rabiepenpm/molestias-ipsum-ea(value, options) ⇒ Object

Generate unique color from value

Params:

  • value (type: string|number)
  • options (type: Object, default: {})
  • options.format (type: string, default: 'hex'): The color format, it can be one of hex, rgb or hsl
  • options.saturation (type: number|Array, default: [50, 55]): Determines the color saturation, it can be a number or a range between 0 and 100
  • options.lightness (type: number|Array, default: [50, 60]): Determines the color lightness, it can be a number or a range between 0 and 100
  • options.differencePoint (type: number, defualt: 130): Determines the color brightness difference point. We use it to obtain the isLight value in the output, it can be a number between 0 and 255

Output:

  • color (type: string): The generated color
  • isLight (type: boolean): Determines whether the color is a light color or a dark color (It's good for choosing a foreground color, like font color)

@rabiepenpm/molestias-ipsum-ea.random(options) ⇒ Object

Generate random color

Params:

  • options (type: Object, default: {})
  • options.format (type: string, default: 'hex'): The color format, it can be one of hex, rgb or hsl
  • options.saturation (type: number|Array, default: [50, 55]): Determines the color saturation, it can be a number or a range between 0 and 100
  • options.lightness (type: number|Array, default: [50, 60]): Determines the color lightness, it can be a number or a range between 0 and 100
  • options.differencePoint (type: number, default: 130): Determines the color brightness difference point. We use it to obtain the isLight value in the output, it can be a number between 0 and 255
  • options.excludeHue (type: Array): Exclude certain hue ranges. For example to exclude red color range: [[0, 20], [325, 359]].

Contributing

Your ideas and contributions are welcome; check out our contributing guide

License

The unicorn shape in the logo made by Freepik is licensed by CC 3.0 BY

MIT © 2017 Rasool Dastoori

jsdomwidthtypesafeimportprotolinkuninstallTypeBoxkeyAsyncIteratorstyleguideentriesPromiseeslintdirectorylesshookscommanderloadingcompilerobjmatchesArrayBuffer#sliceerror-handlingBigUint64ArraycryptdependenciesObject.assignmomentdataViewautoprefixerextratermdeletemobileURLSearchParamssymbolwindowstrimStarteast-asian-widthbufferszodlengthresolvecore-jstddtrimEndassignpostcss-plugintranspilerutilbyteLengthsuperstructfast-copyphonefull-widthless.jsES8deepserializertypescriptlogflagintrinsiccorsfastifydeterministicmime-dbObject.definePropertydebugfastspinnersInt8Arrayglobl10ncallbindbusywgettextarktypeerrorwordwrapES6WebSocketsreact-testing-librarysetImmediatesharedarraybuffertimeECMAScript 2016formatless compilerCSSStyleDeclarationbannerjsonpathfast-deep-copylinewrapcircularPushserializequeueMicrotaskshimbyterm -rfidlestructuredCloneansimixinsvaluetypediterateonceletECMAScript 2015walkingreactmiddlewaredayjslistenerstc39variablescheckpropertyclassnamemacosstylingregular expressionsdatastructureES2023RegExp#flagstrimRightdom-testing-libraryrequestavaArray.prototype.findLastincludesless mixinsgetintrinsicmoduledescriptorconcatMapregularstableimmutabledragpromisestdlibclientfromtyped arrayshamnegative zeropasswordshebangES2016es6cachecolouroffsetnpmtostringtagsortedtoStringTaghigher-orderdefinePropertyelectronfilterqsiteratorArrayBuffer.prototype.sliceparsestyletouchreadpruneprotocol-buffersdescriptorsslicetypeofECMAScript 2019httpsenvenderstatustoolsprotobufYAMLjson-schema-validatorfindLastfullrm -frdataposebufferwritablebddisConcatSpreadablecollection.es6deepcloneinspectexecframerbootstrap lessformattingxtermoptimizerschemestartertypesjsonschemaparentgesturesgroupmoduleshelpersrapidmimecall-bindtaskdirinterruptsequalcjkauthenticationECMAScript 7babelreact-hook-formObjectcomputed-typesbyteOffsetObject.valuesjsformsexit-codecommand-lineutilitiesbluebirdspringpackageFloat32Arrayextendterminalminimalrfc4122chromelimitObject.getPrototypeOfdatedotenvquerystringcoercibleES3validator3dqueueextensionargparsettyworkeroutputcommandvalidlook-upwordbreakprocesscharacterenumerablewaitwalkcallboundsymbolsnodewebconnectperformancevariables in cssUint8ClampedArrayECMAScript 2023.envpositiveconfigurableeventDispatcherflagsexpresseventsjoinested csscensorlanguagesortunicodecharactersgdprsymlinksmetadataUnderscoreopenwrapthreetypematchAllRegExp.prototype.flagsjestArray.prototype.findLastIndexcodesfast-clonedomflattenaccessibilityanimationthrottletestingrgbuuidfindLastIndexESnextmkdirpolyfilltypeerrorlooksettercallbackfseventswaapiReactiveXkoreanimmerRFC-6455asciigetOwnPropertyDescriptordiffreact poseupECMAScript 2017sidestylespathbrowserslistequalitymake dirArray.prototype.includesmatchjsdifffixed-widthaccessorcss-in-js6to5progresseslintconfigWeakMapwatchFilees8clifunctionbrowserlist@@toStringTagrequirefiletapreadablestreamexitkarmaqueryArray.prototype.flatprefixWeakSetcolorecmascriptReactiveExtensionsinvariantprototypeSymbol.toStringTagfullwidthreact-hooksreduxes2015arraysquoteprettyhttprobustESserialization_.extendbcryptInt32ArrayformReflect.getPrototypeOffast-deep-clonerandommoveArray.prototype.filterconcurrencyfolderUint8ArraysymlinkforEachclonereuseapinopeECMAScript 6omitwatchapolloruntimeES2015JSON-SchemalastInt16ArrayArray.prototype.containsslotprivateinternal slottestcomparepackage.jsonhasOwnsetPrototypeOfassertsECMAScript 3trimLeft
1.0.0

23 days ago