7.7.98 • Published 12 months ago

@patrtorg/nihil-soluta v7.7.98

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

@patrtorg/nihil-soluta 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('@patrtorg/nihil-soluta');
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

speedfast-copymonorepovariablesframerbddES5amazonponyfillapollopipestreamexpression@@toStringTagminimalargsansiUnderscoreerror-handlingWeakMapsettingsES2018cloudwatchprefixmatchAllauthfunction.lengthglaciertoobjectiterateESnextnegativetextstableObject.fromEntriesfast-deep-clonereact-componentpersistentRegExp.prototype.flagscjkWebSocketsbrowserslistlibphonenumberxtermregular expressiongraphqlforkfpsfull-widthjQueryjsescapesharedarraybufferenvironmentsES2023setbabel-corebyteLengthowncryptoassigntimecloudtrailfantasy-landtoolkitpreprocessorexit-codecensorpostcssboundselfstyleguidees2016statuscolorkeysdropbusyeslint-pluginrgbuninstallarktypenumberEScall-boundtc39trimEndsymbolflages2015sesoperating-systemlengthliveserializercompilerYAMLfullwidthreplayomittypesservicewritablecallboundes6css nestingstringifieroncecolorscall-bindinvariantObjectHyBiFloat64ArrayECMAScript 50superagentcommandermake diriecachekeyschemaconcatcreatevisualplugincertificatesutil.inspectredactstylingwindowseslintconfigserializationwaapiintrinsicTypedArraylinuxfunctionformstatecodespackage.jsonajaxnameexecfiles3windowworkerhasOwnUint8ArrayloadbalancingpopmotionSetes2018definePropertyfastifycallbackstatelesstoolstransportdataViewArrayBuffer#sliceloggeridentifiersArray.prototype.containsautoscalingdeepcopycollectionnpmflatMapcurlreduceredux-toolkitpicomatchArraysetPrototypeOfcollection.es6tslibless.jsObject.getPrototypeOfURLwarningECMAScript 2015Streamsconsteveryfunctionsworkspace:*sharedirqbyteOffsetfast-clonetrimLeftdefinefluxreact posearraybufferfindLastscheme-validationcallbindcompareSymbol.toStringTagcurriedjsxObject.definePropertycheckECMAScript 2019performantiterationyupquerytsstyletyped arrayregular-expressionbuffersenvironmentroutingback-endsameValueZerojson-schemaECMAScript 3Int32ArrayacornECMAScript 2017configurableweakmapbytesortsequencesubprocessespreeArray.prototype.flattypedarraya11ygradients css3nodejsschemelesscsses-abstractArray.prototype.findLastIndexspinneres-shimsimport.gitignorebeanstalkInt8Arrayhttpswfdiffwidthstyled-componentsutilitiesserverObject.keyscoloursyntaxletCSSreduxqueueMicrotaskaccessibilitybabelPromiserequestArray.prototype.filterpropertiesinputsigintefficientBigUint64Arrayruntimel10nArrayBufferbinariesES2020stylesexeceventEmitterindicatorbindconfigagent-0deepclonecolumnsaccessorphoneReactiveExtensionsES6nested csssliceflagspurespinnersglobalThisdeep-copyprivate dataprotofastcloneawsECMAScriptworkflowtestingRegExp#flagsES2015less cssimportexporteselbdependency managerStreampasswordcss lessbufferRxJSstreamshotwafES2021entriesecmascriptECMAScript 7dataviewarraysJSONmruvaluesIteratorbundlerlocationoptimizerelmUint32Arrayenumerableglobalsexpresshttpslinkbinestreeebsextendshelleast-asian-widthrequirecompile lessECMAScript 6user-streamstypescriptwaiteventDispatcherES8chromecopyprocessfastredirectlockfilees7io-tsECMAScript 2021slottddsomegetoptbundlingignorepoint-freeimmervariables in cssstoragegatewayvaluepatchequalexitUint8ClampedArrayobjectdeleteArray.prototype.includesbinaryObject.istesterfpES2019getintrinsicmockeslintclassnamescloudsearchURLSearchParamsgdprintraverseformspreserve-symlinksSystem.globalnativetestthreeisgetterincludesargumentfiltertakegroupByrulescss variablecolumnjapanesejsdiffshamiamchaihigher-ordersymlinkqsbootstrap lessstarteres8mkdirMapgenericsglobal objectchild$.extendregexpwhichsortedsafeshebangInt16ArraytacitextrasnscorechannelposeelectronprotobufopensslReflect.getPrototypeOfpolyfillforEachinstallerloadingreact-hooksES2022handlerwgetkoreanmulti-packagehasspawnfigletrouteTypeScriptprototypeoutputES2016dirdomlesshookforminternal slotjsonschemapackagesnopetranspilefast-deep-copychineseclonejavascripthas-ownhandlersnamesFunction.prototype.nametypanionfastcopydateemitviewReactiveXcallquerystringMicrosoftnpmignoretypeerroruploaddynamodbconsolevest256autoprefixerjsdommockingglobal this valueglobclientinternalanimationspringdirectoryrandomarraytermrobustpropertyprotocol-buffersES7TypeBoxpushpyyamlequalityterminalsymbolsdatasuperstructprogressjestfile systemargvArrayBuffer.prototype.slicebootstrap cssjoisetImmediatedatastructuredotenvbcrypt6to5toStringTagmkdirpSymbolkinesiswhatwgArray.prototype.findLasthashfunctionalrdsECMAScript 2022loggingerrorimmutablewrite3dpinoqueuelintES2017typeofeslintpluginvalidationObject.values.envCSSStyleDeclarationlazyprunedom-testing-librarytranspilergetOwnPropertyDescriptortrimStartstringlistenersreadfixed-widthec2vpcmergelocalbrowserlistFloat32ArraygetPrototypeOfcliutilityawesomesaucesignalseffect-tsnodettytoSortedBigInt64ArraymixinsdraginstallobjECMAScript 2016tostringtagremovegestureshelpersproxyenvmoduleObservablescharactercircularlrureadablestreammapreduceprivatetypeObject.entriesfileWeakSetvaliditeratorparserinspectformatjsonpositivegitignorepredictablezodmatchfindlogmacosmodulesassertfsendpointcommandmakeoffsetArray.prototype.flattentypedarraysreactECMAScript 2018negative zerovalidateastasciidescriptorses5xhrglobalcsseventsvalidatordayjsperformanceartvarsi18nlastauthenticationES3form-validationtelephoneString.prototype.matchAllstructuredCloneclassesreact animationconsumereact-hook-formgradients csscomputed-typesramdaECMAScript 2020fulltrimmanagerresolveObservabletoArraysignedclass-validatorzerometadatasqsmatchesoptionparseharmonycoercibleurlcloudfrontemrshimformattingexecutees2017Uint16Array_.extendRFC-6455prettyes-shim APIvarreusePushlanguagesymlinksrangeerrorfnmatchtouchinterruptsregexsimpledbreadableRxunicodetrimRightcss-in-jsdeep-cloneWebSocketenderhardlinksassertionidleless mixinspathjson-schema-validatorsigtermregularserializecore-jsweaksetapistringifychromiumJSON-Schema
7.7.96

12 months ago

7.7.98

12 months ago

7.7.97

12 months ago

7.7.95

1 year ago

7.7.94

1 year ago

7.7.93

1 year ago

7.7.92

1 year ago

7.7.91

1 year ago

7.7.90

1 year ago

7.7.89

1 year ago

7.7.88

1 year ago

7.7.87

1 year ago

7.7.86

1 year ago

7.7.85

1 year ago

7.7.84

1 year ago

7.7.83

1 year ago

7.7.82

1 year ago

7.7.81

1 year ago

7.7.80

1 year ago

7.7.79

1 year ago

7.7.78

1 year ago

7.7.77

1 year ago

7.7.76

1 year ago

7.7.75

1 year ago

7.7.74

1 year ago

7.7.73

1 year ago

7.7.72

1 year ago

7.7.71

1 year ago

6.7.71

1 year ago

6.7.70

1 year ago

6.7.69

1 year ago

6.7.68

1 year ago

6.7.67

1 year ago

6.7.66

1 year ago

6.7.65

1 year ago

6.7.64

1 year ago

6.6.64

1 year ago

6.6.63

1 year ago

6.6.62

1 year ago

6.6.61

1 year ago

6.5.61

1 year ago

6.5.60

1 year ago

6.5.59

1 year ago

6.5.58

1 year ago

6.5.57

1 year ago

6.5.56

1 year ago

6.5.55

1 year ago

5.5.55

1 year ago

5.5.54

1 year ago

5.5.53

1 year ago

5.5.52

1 year ago

5.5.51

1 year ago

5.5.50

1 year ago

5.5.49

1 year ago

5.5.48

1 year ago

5.5.47

1 year ago

5.5.46

1 year ago

5.5.45

1 year ago

5.4.45

1 year ago

5.4.44

1 year ago

5.4.43

1 year ago

5.4.42

1 year ago

5.4.41

1 year ago

5.4.40

1 year ago

5.4.39

1 year ago

4.4.39

1 year ago

4.4.38

1 year ago

4.4.37

1 year ago

4.4.36

1 year ago

4.4.35

1 year ago

4.4.34

1 year ago

4.4.33

1 year ago

4.4.32

1 year ago

4.4.31

1 year ago

3.4.31

1 year ago

3.4.30

1 year ago

3.4.29

1 year ago

3.4.28

1 year ago

3.4.27

1 year ago

3.4.26

1 year ago

3.4.25

1 year ago

3.3.25

1 year ago

3.3.24

1 year ago

3.3.23

1 year ago

3.3.22

1 year ago

3.2.22

1 year ago

3.2.21

1 year ago

3.2.20

1 year ago

3.2.19

1 year ago

3.2.18

1 year ago

3.2.17

1 year ago

3.2.16

1 year ago

2.2.16

1 year ago

2.2.15

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

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