3.8.116 • Published 10 months ago

@patrtorg/consequatur-distinctio v3.8.116

Weekly downloads
-
License
MIT
Repository
github
Last release
10 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

10 months ago

3.8.115

10 months ago

3.8.116

10 months ago

3.5.91

11 months ago

3.5.90

11 months ago

3.6.100

10 months ago

3.5.89

11 months ago

3.5.88

11 months ago

3.8.111

10 months ago

3.8.112

10 months ago

3.8.113

10 months ago

3.8.110

10 months ago

3.8.108

10 months ago

3.8.109

10 months ago

3.8.100

10 months ago

3.8.101

10 months ago

3.7.100

10 months ago

3.8.102

10 months ago

3.8.103

10 months ago

3.8.104

10 months ago

3.8.105

10 months ago

3.8.106

10 months ago

3.8.107

10 months ago

3.6.99

10 months ago

3.6.98

10 months ago

3.6.97

10 months ago

3.6.96

10 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

11 months ago

3.5.87

11 months ago

3.5.86

11 months ago

3.5.85

11 months ago

3.5.84

11 months ago

3.4.84

11 months ago

3.4.83

11 months ago

3.4.82

11 months ago

3.4.81

11 months ago

3.4.80

11 months ago

3.4.79

11 months ago

3.4.78

11 months ago

3.4.77

11 months ago

3.4.76

11 months ago

3.4.75

11 months ago

3.4.74

11 months ago

3.4.73

11 months ago

3.3.73

11 months ago

2.3.73

11 months ago

2.3.72

11 months ago

2.3.71

11 months ago

2.3.70

11 months ago

2.3.69

12 months ago

2.3.68

12 months ago

1.3.68

12 months ago

1.3.67

12 months ago

1.3.66

12 months ago

1.3.65

12 months ago

1.3.64

12 months ago

1.3.63

12 months ago

1.3.62

12 months ago

1.3.61

12 months ago

1.3.60

12 months ago

1.3.59

12 months ago

1.3.58

12 months ago

1.3.57

12 months ago

1.2.57

12 months ago

1.2.56

12 months ago

1.2.55

12 months ago

1.2.54

12 months ago

1.2.53

12 months ago

1.2.52

12 months 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