7.7.98 • Published 10 months ago

@patrtorg/nihil-soluta v7.7.98

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

10 months ago

7.7.98

10 months ago

7.7.97

10 months ago

7.7.95

10 months ago

7.7.94

10 months ago

7.7.93

10 months ago

7.7.92

10 months ago

7.7.91

10 months ago

7.7.90

10 months ago

7.7.89

10 months ago

7.7.88

10 months ago

7.7.87

10 months ago

7.7.86

10 months ago

7.7.85

10 months ago

7.7.84

10 months ago

7.7.83

10 months ago

7.7.82

10 months ago

7.7.81

10 months ago

7.7.80

10 months ago

7.7.79

10 months ago

7.7.78

11 months ago

7.7.77

11 months ago

7.7.76

11 months ago

7.7.75

11 months ago

7.7.74

11 months ago

7.7.73

11 months ago

7.7.72

11 months ago

7.7.71

11 months ago

6.7.71

11 months ago

6.7.70

11 months ago

6.7.69

11 months ago

6.7.68

11 months ago

6.7.67

11 months ago

6.7.66

11 months ago

6.7.65

11 months ago

6.7.64

11 months ago

6.6.64

11 months ago

6.6.63

11 months ago

6.6.62

11 months ago

6.6.61

11 months ago

6.5.61

11 months ago

6.5.60

11 months ago

6.5.59

11 months ago

6.5.58

11 months ago

6.5.57

11 months ago

6.5.56

11 months ago

6.5.55

11 months ago

5.5.55

11 months ago

5.5.54

11 months ago

5.5.53

11 months ago

5.5.52

12 months ago

5.5.51

12 months ago

5.5.50

12 months ago

5.5.49

12 months ago

5.5.48

12 months ago

5.5.47

12 months ago

5.5.46

12 months ago

5.5.45

12 months ago

5.4.45

12 months ago

5.4.44

12 months ago

5.4.43

12 months ago

5.4.42

12 months ago

5.4.41

12 months ago

5.4.40

12 months ago

5.4.39

12 months ago

4.4.39

12 months ago

4.4.38

12 months ago

4.4.37

12 months ago

4.4.36

12 months ago

4.4.35

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