3.8.116 • Published 11 months ago

@patrtorg/consequatur-distinctio v3.8.116

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Overview

@patrtorg/consequatur-distinctio is a fast and lightweight javascript library for generating unique and beautiful colors from any texts or numbers.

Why @patrtorg/consequatur-distinctio?

  • There is no need to store colors in the database anymore, just use @patrtorg/consequatur-distinctio 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 @patrtorg/consequatur-distinctio
# or
$ yarn add @patrtorg/consequatur-distinctio

ES6 Import:

import @patrtorg/consequatur-distinctio from '@patrtorg/consequatur-distinctio';

CommonJS (like nodejs, webpack, and browserify):

const @patrtorg/consequatur-distinctio = require('@patrtorg/consequatur-distinctio');

AMD (like RequireJS):

define(['@patrtorg/consequatur-distinctio'], function (@patrtorg/consequatur-distinctio) {
  // ...
})

Using <script>

Include @patrtorg/consequatur-distinctio.js or @patrtorg/consequatur-distinctio.min.js into your html file:

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

Usage

/* Generate unique color from texts or numbers */

@patrtorg/consequatur-distinctio('Hello world!')
// { color: "#5cc653", isLight: true }

@patrtorg/consequatur-distinctio('bf545d4c-5360-4158-a572-bd3e204185a9', { format: 'rgb' })
// { color: "rgb(128, 191, 64)", isLight: true }

@patrtorg/consequatur-distinctio(123, {
  saturation: [35, 70],
  lightness: 25,
})
// { color: "#405926", isLight: false }

@patrtorg/consequatur-distinctio(123, {
  saturation: [35, 70],
  lightness: 25,
  differencePoint: 50,
})
// { color: "#405926", isLight: true }

// Generate random color
@patrtorg/consequatur-distinctio.random()
// { color: "#644cc8", isLight: false }

// Generate a random color with HSL format
@patrtorg/consequatur-distinctio.random({ format: 'hsl' })
// { color: "hsl(89, 55%, 60%)", isLight: true }

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

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

Examples

API

@patrtorg/consequatur-distinctio(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)

@patrtorg/consequatur-distinctio.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

uninstallappkarmastyled-componentsInt16ArrayqueueReflect.getPrototypeOfimmutablefunction.lengthescapeshimdomkeyswaapideepcopyObject.fromEntriespinofastaccessoreslint-plugincallhigher-ordercollectiontermasciiECMAScript 2019react-hook-formlintregular-expressionwarningcallbindRFC-6455someECMAScript 2020parentebssimpledbspinnershookformArrayform-validationeventDispatcherECMAScriptUint32ArraydebugStreamartcall-boundes-abstractinputgetPrototypeOfshamhas-ownarraysistanbulECMAScript 2022nativegroupByajvidentifiersvestgetintrinsicObject.entriesmonoreporedactespnpm9channelECMAScript 2016call-bindtddECMAScript 2017descriptorsuuidstringifyindicatorECMAScript 6fast-copyReactiveXworkspace:*pathObject.assigntc39regexpsearchtypeerrorrmdirexecutetoSortedcurleast-asian-widthpropprotocurriedjsprotobufcontainsparentsreduxownflatMapansi256loadingjasminetsio-tscommand-lineclassname-0file systemxmlUint8ArrayreuseBigUint64ArrayURLfpsestreepackage managerpatchfullawesomesaucecoreapollo__proto__manipulationSymbol.toStringTagweakmaptslibargumentES2023requestcoercibleTypeBoxArrayBuffer#sliceletstreamsES2022react posesyntaxerrorArray.prototype.findLastArrayBufferECMAScript 2018dataES2015outputchaiqueueMicrotaskarktypeMapstoragegatewaydayjsoptimizerroute53ES8streameffect-tsglobalssettingsreact-testing-libraryArray.prototype.includesutilTypedArraytapeformsdeterministicfastclonenamesutilsECMAScript 5parsebabel-corefast-deep-cloneglobalThisajaxstringifiersideglobmkdirspopmotionframerenvironmentsbyteLengthSymbolsnstrimEndefficientacornmatchfsclassnamescode pointsboundelasticacheECMAScript 2023json-schema-validationwidthhasOwnPropertynpmRegExp#flagsYAMLvalidfpemitttyroutevalidationchildcolorworkerfast-deep-copydynamodbimportexportinstallObservablesES2021csscryptovaluedragtypetoobjectsetseslastproxydatetestingIteratorstringrulespoint-freepromiseArray.prototype.findLastIndexargsfindLastcloudformationbrowserslistrfc4122eslintconfiggetapiwindownumberassertionlook-uprgb@@toStringTaggitignorebinaries3dObject.getPrototypeOfasterisksbddcolumnsreversetextregular expressionspruneStreamscharacterscss-in-jsunicodemkdirgetterPromisebuffervisualfeedloggerArrayBuffer.prototype.slicedataviewcloudwatchArray.prototype.flatteninframeworkhelpersdefinegetoptcharacterpicomatchbinspeedidexecfiletapprogresslistenersvariablesminimalhtmlmoveec2inspectvararraybufferglobalCSSStyleDeclarationprototypeterminalassignquerystringfigletpropertiestypestakekinesisimmerrecursiveposegroupfilesetPrototypeOfjsdomsortedjsdiffrm -fres-shimsObservableread[[Prototype]]syntaxharmonyconsumetoArraymake dirdependenciesforEachjQueryshebangsource mapAsyncIteratordiffUint8ClampedArrayes-shim APIswfnamecopypyyamlurlhashinferencejshintObject.valuesextraWebSocketsforkmobilemomentpackagelengthtimezxhaswebtypedarrayautoscalingcachepipesqsgesturespackages.gitignoreenderrestfnmatchCSSxhrFloat32ArrayRegExp.prototype.flagstestermatchesclijsonbundlingwriteanimationreadablestreamvalidatejapaneseregularhttpsvpctypesafetouch_.extendcloneBigInt64Arraydropemroptimistmapsuperstructcomputed-typescompilerArray.prototype.filtertrimStartmanagerpurequoteagentpostcss-pluginfullwidthes5typescriptreact-hooksgetOwnPropertyDescriptorcreatefastifylogInt8ArrayinternalReactiveExtensionsES6makebrowserlistES7fast-clonelruslotUnderscoreeveryiamwritabletoStringTagoncereduceArray.prototype.flatcallboundcollection.es6prettyendpointuser-streamsbabelchecklocationtoReversedESnextasyncomitcolourelbs3fixed-widthlocalfunctionalrssnpmignoreecmascriptjson-schemadirectorypushbusyponyfillWeakSetrm -rfsymlinksObjectobjectcircularconsolelookes2016binarycolumnperformantObject.keysdom-testing-librarySetconcatfindinstallerflagsUint16ArrayES3
3.8.114

11 months ago

3.8.115

11 months ago

3.8.116

11 months ago

3.5.91

12 months ago

3.5.90

12 months ago

3.6.100

11 months ago

3.5.89

12 months ago

3.5.88

12 months ago

3.8.111

11 months ago

3.8.112

11 months ago

3.8.113

11 months ago

3.8.110

11 months ago

3.8.108

11 months ago

3.8.109

11 months ago

3.8.100

11 months ago

3.8.101

11 months ago

3.7.100

11 months ago

3.8.102

11 months ago

3.8.103

11 months ago

3.8.104

11 months ago

3.8.105

11 months ago

3.8.106

11 months ago

3.8.107

11 months ago

3.6.99

11 months ago

3.6.98

11 months ago

3.6.97

11 months ago

3.6.96

11 months ago

3.6.95

11 months ago

3.6.94

11 months ago

3.6.93

11 months ago

3.6.92

11 months ago

3.6.91

12 months ago

3.5.87

12 months ago

3.5.86

12 months ago

3.5.85

12 months ago

3.5.84

12 months ago

3.4.84

12 months ago

3.4.83

12 months ago

3.4.82

12 months ago

3.4.81

12 months ago

3.4.80

12 months ago

3.4.79

12 months ago

3.4.78

12 months ago

3.4.77

12 months ago

3.4.76

12 months ago

3.4.75

12 months ago

3.4.74

12 months ago

3.4.73

1 year ago

3.3.73

1 year ago

2.3.73

1 year ago

2.3.72

1 year ago

2.3.71

1 year ago

2.3.70

1 year ago

2.3.69

1 year ago

2.3.68

1 year ago

1.3.68

1 year ago

1.3.67

1 year ago

1.3.66

1 year ago

1.3.65

1 year ago

1.3.64

1 year ago

1.3.63

1 year ago

1.3.62

1 year ago

1.3.61

1 year ago

1.3.60

1 year ago

1.3.59

1 year ago

1.3.58

1 year ago

1.3.57

1 year ago

1.2.57

1 year ago

1.2.56

1 year ago

1.2.55

1 year ago

1.2.54

1 year ago

1.2.53

1 year ago

1.2.52

1 year ago

1.2.51

1 year ago

1.2.50

1 year ago

1.2.49

1 year ago

1.2.48

1 year ago

1.2.47

1 year ago

1.2.46

1 year ago

1.2.45

1 year ago

1.2.44

1 year ago

1.2.43

1 year ago

1.2.42

1 year ago

1.2.41

1 year ago

1.2.40

1 year ago

1.2.39

1 year ago

1.2.38

1 year ago

1.2.37

1 year ago

1.2.36

1 year ago

1.2.35

1 year ago

1.2.34

1 year ago

1.2.33

1 year ago

1.2.32

1 year ago

1.2.31

1 year ago

1.2.30

1 year ago

1.2.29

1 year ago

1.2.28

1 year ago

1.2.27

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago