2.2.19 • Published 1 year ago

@devtea2027/vitae-facere-tenetur-ut v2.2.19

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@devtea2027/vitae-facere-tenetur-ut Version Badge

github actions coverage License Downloads

npm badge

Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for fully completed data descriptors and accessor descriptors.

Usage

const isDescriptor = require('@devtea2027/vitae-facere-tenetur-ut');
const assert = require('assert');

const defaults = { configurable: false, enumerable: false };
const dataDefaults = { ...defaults, writable: false};

assert.ok(isDescriptor({ ...dataDefaults, value: 'foo' }));
assert.ok(isDescriptor({ ...defaults, get() {}, set() {} }));
assert.ok(!isDescriptor({ ...defaults, get: 'foo', set() {} }));

You may also check for a descriptor by passing an object as the first argument and property name (string) as the second argument.

const obj = { foo: 'abc' };

Object.defineProperty(obj, 'bar', { value: 'xyz' });
Reflect.defineProperty(obj, 'baz', { value: 'xyz' });

assert.equal(isDescriptor(obj, 'foo'), true);
assert.equal(isDescriptor(obj, 'bar'), true);
assert.equal(isDescriptor(obj, 'baz'), true);

Examples

value type

Returns false when not an object

assert.equal(isDescriptor('a'), false);
assert.equal(isDescriptor(null), false);
assert.equal(isDescriptor([]), false);

data descriptor

Returns true when the object has valid properties with valid values.

assert.equal(isDescriptor({ ...dataDefaults, value: 'foo' }), true);
assert.equal(isDescriptor({ ...dataDefaults, value() {} }), true);

Returns false when the object has invalid properties

assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false);
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false);
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'baz' }), false);
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'baz' }), false);
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', get() {} }), false);
assert.equal(isDescriptor({ ...dataDefaults, get() {}, value() {} }), false);

false when a value is not the correct type

assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'foo' }), false);
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'foo' }), false);
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', writable: 'foo' }), false);

accessor descriptor

true when the object has valid properties with valid values.

assert.equal(isDescriptor({ ...defaults, get() {}, set() {} }), true);
assert.equal(isDescriptor({ ...defaults, get() {} }), true);
assert.equal(isDescriptor({ ...defaults, set() {} }), true);

false when the object has invalid properties

assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, bar: 'baz' }), false);
assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'baz' }), false);
assert.equal(isDescriptor({ ...defaults, get() {}, writable: true }), false);
assert.equal(isDescriptor({ ...defaults, get() {}, value: true }), false);

Returns false when an accessor is not a function

assert.equal(isDescriptor({ ...defaults, get() {}, set: 'baz' }), false);
assert.equal(isDescriptor({ ...defaults, get: 'foo', set() {} }), false);
assert.equal(isDescriptor({ ...defaults, get: 'foo', bar: 'baz' }), false);
assert.equal(isDescriptor({ ...defaults, get: 'foo', set: 'baz' }), false);

Returns false when a value is not the correct type

assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'foo' }), false);
assert.equal(isDescriptor({ ...defaults, set() {}, configurable: 'foo' }), false);
assert.equal(isDescriptor({ ...defaults, get() {}, configurable: 'foo' }), false);

Related projects

You might also be interested in these projects:

  • is-accessor-descriptor: Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
  • is-data-descriptor: Returns true if a value has the characteristics of a valid JavaScript data descriptor.
  • is-object: Returns true if the value is an object and not an array or null.

Tests

Simply clone the repo, npm install, and run npm test

toobjectratelimitparseaccessibilityerror-handlingECMAScript 2020sortUnderscoreeventsstreams2s3utilityencryptionbrowserlistes2018functionaltraverse256intrinsicthrottlemake dirstringifyboundECMAScript 5CSStddglobalsArrayBuffergetIteratorqsfetchnegative zerobusyhardlinkscolorredactregexpfindlistenersstringpnpm9ReactiveXUint8ClampedArrayperformantspinnersi18nrobustvariables in csscallObject.getPrototypeOfjestloggerArray.prototype.containsArrayeventDispatcheropenerHyBiWebSocketssigtermpreprocessorjsonpathmodules__proto__iamCSSStyleDeclarationsigintargsreuseassigntestingECMAScript 2018dotenvzodlibphonenumberbreakStreamreal-timees-shim APIcolorsbluebirdequalloadingfile systemruntimesuperstructwidthcolourtoArrayInt16ArraytoolsutilansichromeinterruptsrequestUint16ArraypositivetesterwatchingES2017phonevarssettingsinWeakMapfastifyfunctiontypesafees7deepcopyconnectArray.prototype.flatisemitcommandrandomObject.entriesdescriptorshrinkwrapdeepsliceenvresttypedarraysasyncObjecteast-asian-widthes2017signalnpmdeterministiconceexitflagclassnamesdatastructurerequireRFC-6455loadbalancingendershebangspeedless compilerfull-widthECMAScript 2019chaiArray.prototype.includesmodulees-shimsinferencecreatevisualautoscalingprogresstypedtypedarrayebsdirbeanstalkcligetOwnPropertyDescriptormatchesprunereact-hookspipeeslinthashnamesprocesshotarrayrgbpredictablereducerArray.prototype.findLastIndexES5stylesmrujsonincludesstyleguidequotetrimStarterrorfast-copyjshintnegativegradients cssspinnerexpressiondirectoryflatMaprm -frapisequenceimportexportwordbreakmiddlewareclassescolumnsreduxreadsimpledbparsingpackage.jsonjapanesekinesisescapeutil.inspectargvargumentsvestproxyprotoworkspace:*extendarktypedeep-copyparentsastes2016typeofes8tc39toSortedoptionInt32ArraywatchFileoptimizerES2021iterationhandlerses-abstractbindpreserve-symlinksbyteOffsetcompilerhasOwnPropertyReactiveExtensionsargumentcircularrfc4122keysxdg-openRegExp.prototype.flagsmatchECMAScript 2017validationdependency managerwhatwggroupByECMAScript 6entriesmochadataviewECMAScript 3weakmapcss nestingflatinstalleroperating-systemArrayBuffer.prototype.sliceidtypesidentifiersESnextlimitconcurrencyeslint-pluginpropertystyled-componentsunicodecorevaluesassertpropertiesform-validationfullwidthparentmapreduceassertionstylecharacterowncloudsearchcolumnsymlinkssafeexit-codeinstallindicatoropensiterateString.prototype.trimchildtslibbddinspectURLES2019nested cssbcryptbufferuninstallconcatMapMicrosoftinternalformattingJSON-Schemajasminemobile.envserializerArray.prototype.flatMapuuidefficienttakearraysemojinodehooksmacostaskratereact-hook-formvalidECMAScript 2022fseventsprototypefindLastpersistentstatusstylingdayjsnativecensorperformancetostringtagnamequeueMicrotaskBigInt64ArrayformgetoptresolvepyyamllogginglruesESwebsitefluxbyteLengthlintstylesheetschemespecfastcloneTypedArrayfindLastIndexwatchercopyasciigdprurlsSymbol.toStringTagreactsymlinkyupdebugextratapesqsstoragegatewaycss variablefast-clone@@toStringTagecmascriptWebSocketBigUint64Arrayelbstreamsduplexcharactersregular expressionredux-toolkitprettySymbolcompareJSONtouchreplayenvironmentstypanionquerystringcacheglobvalidatemergeshellgetterxtermcloudwatchavasameValueZeroidleobjectgloballook-upES3has-ownstartergetPrototypeOfcomputed-typesES7snsshamreadablecmdsidecontainsfunctionsauthurllastpostcssES2023private datadescriptionyamlcssstreamuprm -rfObservableshelperstestsymbolsgetintrinsicweaksetlinkforEachlaunchpackage managerstableschemapicomatchjsxqueueMapreadablestreamsetImmediatefromeveryiebootstrap lesslivefast-deep-copyconsolemkdirscommand-linefast-deep-clonesetPrototypeOfrapidwhichoutputxdgenvironmenta11ydynamodbFloat32Array0SetsesjQueryponyfilldiffObject.assignmonorepofsmixinsstaterestfulwarningclassnameES2022coercibleamazongradients css3rmagentcallboundArray.prototype.flattenomitfoldercss lessvariablesdomstatelessmapes6makeArrayBuffer#slicemimesharedarraybufferreduceoptimistinputpolyfillbyte-0recursiveRxJSjsformstrimRightprivatewritableES8RegExp#flagsio-tsfileappAsyncIteratorhookformtyped arraycorshasOwnpatchterminalpromisesWeakSetdependencieseslintpluginexpressdescriptorses5definecode pointsenumerablebrowserslistajvtoStringTagexeclockfileserializefastcopyrouterajaxUint32Arrayfind-upYAMLObject.keysFunction.prototype.namesuperagentweblogec2defaultcollectionpushestreequerytaplesscsselectronemrsetter[[Prototype]]airbnbURLSearchParamsstringifiertypeInt8Arraydebuggermetadatagroupsyntaxerrorfullinternal slotdatecall-bindrangeerrorassertsECMAScript 7elmimportirqcloudfrontmkdirpchinesetypeerrordatautilitiesless.jsdeepcloneguid_.extendchannelwafopenlimitedbundlerStreamsTypeScriptbannercloneeventEmitterdefinePropertywatchtrimEndeditorworkertrimLeftshimmoveES2015bundlingsortedstartl10nserializationcurlroute53callbinddeep-clonewaithttpsjavascriptkeyhttpmomentparserautoprefixercss-in-jslanguagecall-boundkarmabrowsertspasswordmimetypespackageslinuxless cssObject.fromEntriescloudtraildataViewwalkingpackagettydropArray.prototype.findLastequalitywindowsgenericsES2016ECMAScript 2021zerolessminimalfastiteratorlookPromiseUint8ArrayString.prototype.matchAlljwtawesomesauceendpointrmdirmime-dbmatchAllObject.definePropertynopelengthawaitwalksomelinewrappromiserdsvpcviewswfinvariantES6signalsECMAScript 2023immutablewriteextensioncompile lessmkdirreact-testing-libraryObject.ismulti-packagebootstrap cssjsdomObservableclass-validatorchecksharedexeECMAScript 2016telephonecallbackeslintconfigStyleSheetfigletObject.valuestrimjoiprotocol-bufferskoreanfixed-widthexecutablestdlibpropfindupbatchstructuredClonenodejsprefixprotobufauthenticationcodesregexconfigslothasxhrregular expressionselasticacheFloat64Arraychromiumcore-jsflattenworkflowECMAScript 2015immerReflect.getPrototypeOfpostcss-plugindeletefilterdom-testing-libraryformatsinatra$.extendTypeBoxES2018es2015numberframeworkfpstimeArray.prototype.filterglacierhigher-orderwordwrapargparsesymboljsdiffconfigurableregularPushflagsscheme-validationtexttermartwrapES2020Rxsetcommandercollection.es6typescriptspawnawstoolkitthroatcryptarraybuffersearchcjkless mixins
2.2.19

1 year ago

2.2.18

1 year ago

2.2.17

1 year ago

2.2.15

1 year ago

2.2.16

1 year ago

2.2.13

1 year ago

2.2.14

1 year ago

2.2.12

1 year ago

2.2.11

1 year ago

2.2.10

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago