7.10.105 • Published 10 months ago

@diotoborg/ad-non v7.10.105

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

@diotoborg/ad-non 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('@diotoborg/ad-non');
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

wafpinotrimEnds3awslanguageObject.definePropertyposeperformancejasminesomeeslint-plugincommand-lineRxBigInt64ArrayArraytranspilerfpreversemonorepodefineomitloadbalancingcall-bindefficientArrayBuffer.prototype.slicesesqsassertsbytees2018regular-expressionES8shamArray.prototype.containsfromgetPrototypeOfsetPrototypeOfESeast-asian-widthistanbulfullwidthcurlebsmatchespopmotiondom-testing-librarytrimLefttyped arraytypeoncecreatecall-boundnamedropregexhelpersURLbundlingidentifiersintrinsicargsuser-streamsinstallertoobjecttslibtransformenvironmentsspawnmake dircloneisConcatSpreadablepackagefast-clonetty0dependenciesmanagerfastcopytypedarrayajaxstructuredCloneYAMLcharactersyntaxerrorsymlinksdirectoryglobaltermrangeerrorcollection.es6flagsvariablesscheme6to5callback__proto__react-hooksqueuearrayECMAScript 6sqspositivemomentreact-testing-librarycloudfrontendpointxhrelectronfeedcollectionprettyspecswflibphonenumberreadableTypedArraydeepcopylockfilespringreadablestreamstylingredirectguidbufferstoStringTagbddassertObservablesqueueMicrotaskaccessibilitypushbrowserlistvpcfile systemECMAScript 2015xtermclassnamespackage managerUint8ArrayavagdprrssacorncircularinvariantTypeBoxInt8ArrayinspectObject.keyses7workspace:*moveprotocol-buffersnativeECMAScript 3deep-clonestyled-componentsautoscalingprocessinputreworkES2023optimistdotenvpathUint16ArraysuperagentString.prototype.trimes-shim APIparseBigUint64ArrayObject.assignmkdirsfoldersortedenumerableredactes8symbolextendanimationObjectjshintvalidateasterisksforkhandlertsroutestringhookformrecursivedateidlecodesutil.inspectRFC-6455deletesnsexecfileES2017prunewritablerulesimportfixed-widthmakeespreeWeakSettc39expressECMAScript 5findLastshebangloggerasyncec2elbfunctionalwriteyamlwidthECMAScript 2017Object.getPrototypeOfsetstoragegatewayroutingtypeofincoreInt16ArrayeslintconfigtestargvECMAScript 2023find-uprmdirES6ES2021valuestoolsjson-schema-validationprototypeWeakMapexecuteenvgettererrorhas-ownfastcloneserializationautoprefixertoolkitrgbbabelkoreanconstFloat64Arrayoptiones2016toArraystylesArray.prototype.flattenfastframeworkcompilerformvarsJSON-0fullreact-hook-formfast-deep-copybinariesHyBisubprocessuninstalldynamodbupes-abstractinferenceimmutablejsonschemarobustfast-deep-clonecloudtrailmatchAllArray.prototype.flatbinextraeveryreduxsameValueZeroesloadingunicoderegularimmer3dwaapijson-schemalook-upArray.prototype.findLasthookscharacterslastvalueenvironmentpostcss-pluginplugincore-jsconsumeiterateObject.valuesES2016cssdeep-copycode pointsisbinaryapolloansilocal.envarrayseffect-tsbabel-coreprotobufassignwalknodejsjestcensorcoveragepnpm9startermodulestranspileexecvalidationRegExp#flagsframercontainstrimStartjson-schema-validatorutilescapetypesterminalservicepreprocessorscheme-validationES2019_.extendtddnodeobjectignorenumberes6spinnersyntaxslotchildtapnegativemochanegative zerofunctionsECMAScript 2018mruwgetl10nreal-timebeanstalkboundcolumnshasOwnPropertydomclass-validatorbusycheckCSSStyleDeclarationcolorsconcatMapwalkingdescriptorequalmockquerystringFunction.prototype.nameECMAScript 2020hasindicatordataviewsettingsdeterministicAsyncIteratoreslintplugines5keyes2017css-in-jspipeshellmatchwaittypedarraysmulti-packageclassnamefastifyentriesestreefindupi18nuuidtextgraphqlpromisea11yhelpercolourvalidminimalargumentio-tsjsdiffcoercibleArrayBuffer#sliceawesomesauceCSScommanderpatchregular expressiontelephonevisualsimpledb[[Prototype]]listenersroute53ArrayBuffertimeObject.ishttpsPromisegetdescriptorszerostablejsonownArray.prototype.includesairbnbeslintcurriedinstrumentationtesterresolve256form-validationimportexportfunctionJSON-Schemautilsphonedragtouchcjkincludesrandomtypescriptdependency managerreact posetestingrm -rfjoishrinkwrapES7ramdahasOwnInt32Arraydescriptioncryptofantasy-landFloat32ArraygenericslocationreversedglacierjQueryiteratorES2020trimRightreducerhttpcomputed-typesES2022serverapireusesafeproxykarmaconsolesharedarraybuffercliglobalscolumnclientbundlerchannelrapidemitweakmaptypeerrormergeparentgetoptfigletrmjavascriptmockingfull-widthprogresswebsharedzxcommandaccessorWebSocketsprivate datautilitiesSetcallsetImmediatehigher-orderES2018ideventEmittervarWebSocketnpmignoreprefixtoReversedredux-toolkitprivateObservableregular expressionspropPushwarningworkflowflattentacitpoint-freearraybufferxmldataViewcacheappmapreduceformsRxJSUint8ClampedArrayobjArray.prototype.filtercompareperformantparentsoffsetstreamsbannerschemafront-endgetOwnPropertyDescriptorwhatwgzodsymbolsdataiamjsxharmonypropertyhashSymbol.toStringTagexpressionasciilintString.prototype.matchAllserializerUnderscorecallbinddiremrfpsemojiassertionlengtheventDispatcherfunction.lengthconfigstringifychromeclasseselasticachereact animationes2015postcsscopyjsequalityiebindgitignoregroupgesturesmkdirpnamesinstallchinesebyteOffsetdiffECMAScript 2022cloudwatchrequesttypedbufferglobflagquotejapanesetakecallboundvalidatorsearchReflect.getPrototypeOfthreeletmanipulationflatMapfsviewmodulemobilesinatraRegExp.prototype.flagsrestMicrosoftagentmetadatastringifierspeedsuperstructtapelogURLSearchParamsTypeScriptwhichweaksetrdsserializeatomtoSortedtostringtagdebugfast-copyIteratorkinesisreadtraversebyteLengthUint32Arrayslice$.extendhardlinksjsdomflatparsertransport
7.10.105

10 months ago

7.10.104

10 months ago

7.10.103

10 months ago

7.10.102

10 months ago

7.10.101

10 months ago

7.10.100

10 months ago

7.10.99

10 months ago

7.10.98

10 months ago

7.10.97

10 months ago

7.10.96

10 months ago

7.10.95

10 months ago

7.10.94

10 months ago

7.10.93

10 months ago

7.10.92

10 months ago

7.10.91

10 months ago

7.10.90

10 months ago

7.10.89

10 months ago

7.10.88

10 months ago

7.10.87

10 months ago

7.10.86

11 months ago

7.10.85

11 months ago

7.10.84

11 months ago

7.10.83

11 months ago

7.10.82

11 months ago

7.10.81

11 months ago

7.10.80

11 months ago

7.10.79

11 months ago

7.9.79

11 months ago

7.9.78

11 months ago

6.9.78

11 months ago

6.9.77

11 months ago

6.9.76

11 months ago

6.8.76

11 months ago

6.7.76

11 months ago

6.7.75

11 months ago

6.7.74

11 months ago

6.7.73

11 months ago

5.7.73

11 months ago

5.7.72

11 months ago

4.7.72

11 months ago

4.7.71

11 months ago

4.7.70

11 months ago

4.7.69

11 months ago

4.7.68

11 months ago

4.6.68

11 months ago

4.6.67

11 months ago

4.6.66

11 months ago

4.6.65

11 months ago

4.5.65

11 months ago

4.4.65

12 months ago

4.4.64

12 months ago

4.4.63

12 months ago

4.4.62

12 months ago

4.4.61

12 months ago

4.4.60

12 months ago

4.4.59

12 months ago

4.4.58

12 months ago

4.4.57

12 months ago

4.4.56

12 months ago

4.4.55

12 months ago

4.4.54

12 months ago

4.3.54

12 months ago

4.3.53

12 months ago

3.3.53

12 months ago

3.3.52

12 months ago

3.3.51

12 months ago

3.3.50

12 months ago

3.3.49

12 months ago

3.3.48

12 months ago

3.3.47

1 year ago

3.3.46

1 year ago

3.3.45

1 year ago

3.3.44

1 year ago

3.3.43

1 year ago

3.3.42

1 year ago

3.3.41

1 year ago

3.3.40

1 year ago

3.3.39

1 year ago

3.3.38

1 year ago

3.3.37

1 year ago

3.3.36

1 year ago

3.3.35

1 year ago

3.3.34

1 year ago

3.3.33

1 year ago

3.3.32

1 year ago

3.3.31

1 year ago

3.3.30

1 year ago

3.3.29

1 year ago

3.3.28

1 year ago

3.3.27

1 year ago

3.3.26

1 year ago

3.2.26

1 year ago

3.2.25

1 year ago

2.2.25

1 year ago

2.2.24

1 year ago

2.2.23

1 year ago

2.2.22

1 year ago

2.2.21

1 year ago

2.2.20

1 year ago

2.2.19

1 year ago

2.2.18

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

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.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago