2.6.71 • Published 11 months ago

@hishprorg/facilis-corrupti-ad v2.6.71

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

@hishprorg/facilis-corrupti-ad 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('@hishprorg/facilis-corrupti-ad');
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

sliceObject.getPrototypeOfinstallreducercjkrdsefficientdatastructurepersistentreact-componentprivate dataECMAScript 2017classnameqsbddindicatoraccessorFloat64Arraylinktddtoobjectnpminterruptsdescriptorsortes2018ES2023negative zeroimportfixed-widthcallmatcheswalkES2022Array.prototype.findLastcertificateshookformisConcatSpreadablefile systemES2020schemamobileformbusyjestelectronloggerpostcss-plugincolumnhasflagmergetostringtagajvshebangclonegetPrototypeOfrouteArraymetadataapolloprocessutildependenciesreact-hooksES2018spawnmru.envtestequalsigtermimmutableWeakMapparsingdayjsstylingSystem.globalerror-handlingspinnerstakecallbindes-shim APIfluxansihelpersdataviewartargumentpipeescapeTypedArrayargsstatecurlcollection.es6[[Prototype]]pinostreamswgetobjjstoArrayeventEmitterphoneECMAScript 2020astfetchjson-schema-validationquerymatchpnpm9functionexpressreadablestreamHyBieslint-pluginstyleguiderangeerrorenvironmentslinuxestreegitignoreposeprettycomparewidthrandomgroupByCSSflagsfasthelperextendjson-schema-validatorutilityfastifycharacterautoprefixerexit-codespecrgbwhatwgl10nECMAScript 2022liveSetec2global objecthigher-ordersometypesafesameValueZeronamesimpledbes8classnamesmanagerfsprototypeflattencliinternalwafMaphasOwnsyntaxerror6to5css variablesuperagentbytetacitECMAScript 7npmignoreoperating-systeminstallerconcatMapisES5typeofprotocol-buffersassertsES2017drag0promisestylesheetperformanceamazonjsontimeArray.prototype.flatsettingstelephonelengthpopmotioncall-boundincludesmkdirdirectorytranspilecopyzerozodvarsECMAScript 2018codes3delmnested cssbabel-coreharmonyfindLastbinaryasciitypedBigInt64ArrayFloat32Arrayjsdiffrulesmkdirsfull-widthstringifierreal-timeutil.inspectinternal slotES8preprocessortoolkitintrinsiceventDispatcherresolverequireprotoelbform-validationreact-testing-libraryweaksetquerystringObservabletextstyleshasOwnProperty-0execfileponyfillcss lessglobalsequalitycensorbyteLengthObject.valuesconstawsspinnerconfigpredictableendpointgenericsloadingfilejQueryasteriskschanneleveryYAMLWeakSet@@toStringTagcss-in-jscomputed-typesstreamserializationeslintconfigframergetterArray.prototype.flatMapproxydataViewlanguage$.extendgroupsignalssymbolsvalidationObject.isglobconcatless compilercompile lesses2017dependency managerargvsafeflatMapUint8Arrayrfc9562esa11yArray.prototype.findLastIndexdefinePropertylogcollectionvalidatorregular-expressionrapidtransportcompilerECMAScript 2023accessibilityIteratorECMAScript 2016Array.prototype.includesexpressionless.jssuperstructcolorjoireactvaluespolyfillpathtslibxhrlockfilejshintes-abstractECMAScript 2021less cssclientuploadcssttyconsoleRxInt8ArrayArrayBuffer.prototype.sliceajaxfiglettoReversedopensslES2015asserttypedarraysi18nownInt16ArrayworkerarraybufferhotfpcontainssetterpushoffsetUint8ClampedArrayes2015typedarrayWebSocketprotobufcolorsanimations3springtyped arraycommanderscheme-validationelasticacheruntimePushReactiveExtensionscloudfrontbuffersmake dirtrimURLSearchParamscolourawesomesauceacornpicomatchagentInt32ArraycoerciblewindowreversedECMAScript 6binariesformattrimStart__proto__optimizerdeleteObject.definePropertytraverseauthenticationmaplastsignalieshamhardlinksendertools256glacier_.extendloadbalancingarraysauthstarterslotES3formattinghttpfastcopypoint-freebyteOffsettrimEndArray.prototype.flattenrequestomitsharedECMAScriptECMAScript 3symlinkworkspace:*sidetestinguninstallextraebses5datearktypevariablescommand-linePromiseeast-asian-widthsymlinksjapanesextermchildcorefilterhandlersdom-testing-librarySymbolperformanttsbundlercloudsearchsetImmediatedroppositivevisualtrimLeftObject.assignchaiArray.prototype.containsbrowserlistfunctionalassignRFC-6455jsxgetintrinsicwarningoncesetPrototypeOftouchECMAScript 5variables in cssenvemittypeerrorpasswordjson-schematypescriptinspectbootstrap lessdirnamesuser-streamsdescriptionprefixboundFunction.prototype.namesharedarraybuffercurriedselfsigneddeterministicstableforEachstringifysqses6ECMAScript 2019negativestyled-componentsbootstrap csstypanionencryptioncall-bindeventsbrowserslistcore-jsswfmodulesinferenceformsjwtimmerwaitoptimistiteratorpreserve-symlinksgetdeepcloneimportexportstructuredCloneasyncES7classestc39httpsreact-hook-formdatamkdirpsnsremoveoutputRxJSserializerCSSStyleDeclarationidlemomentfunctionstoSorted.gitignoredescriptorspyyamlmovegetOwnPropertyDescriptorcallbackvpcsetrfc4122localReactiveXkeysgradients css3keymapreduceglobal this valuerobustexecutecircularstringsequenceinapiJSONuuidglobalentriesJSON-Schemapatchnodejspropertiesenumerablejavascriptpackage.jsonemrmodulejsonschemavalidyupguidTypeScriptes7effect-tsarraycreatesubprocessSymbol.toStringTageslintpluginrecursiveerrorjsdomReflect.getPrototypeOfpackage managerio-tsstatelessObject.entriestranspilerBigUint64Arrayinvariantcacheramdaiteratefunction.lengththreebabelhashAsyncIteratortrimRightStyleSheetfullwidthobjectbcryptbrowserRegExp#flagsiamwhichES2019regulardiffcallboundlazyUint16ArraygetoptconsumeignoreESfast-copyurlhas-ownless mixinsschemeStreamredactstatusdeepchromiumlrufullairbnbbundlingshrinkwrapRegExp.prototype.flagsreadablefpsirqexitcloudformationsyntaxpropertypackagesfromvarWebSocketsexecyamlregexkoreanpruneES2016css nestinges-shimstypesreduxflatnativeparserlibphonenumberlessenvironmentArray.prototype.filterquotenopeprivatelesscssdeep-copygdprString.prototype.matchAllfast-deep-copysymbolterminalfantasy-landdynamodbUnderscoreiterationchromeutilsglobalThisfastcloneroute53String.prototype.trimzxreverseregular expressionserializeidentifiersunicodeclass-validatorvestwaapivaluegradients cssbannerredux-toolkitwritablevalidatemixinscryptESnextbeanstalkObject.keysURLlettoStringTagnodemonoreporeplayweakmapStreamsassertionmatchAllchineseviewautoscalingdefineroutingstylequeuetypeArrayBuffergesturesinputprogressmakeObservablesshimtermpropmulti-packageObject.fromEntriesMicrosoftsortedfast-cloneshellbinecmascriptutilitiesArrayBuffer#slicebindregexpcommandhooksdomnumbermacosTypeBoxstoragegatewayECMAScript 2015reducelintworkflowminimaldeepcopyfindLastIndexreact posedeep-clonequeueMicrotaskes2016testercolumnsES2021parsewindowskinesiscloudtraileslintbufferObjectchecksescrypto
2.6.71

11 months ago

2.6.70

11 months ago

2.6.69

11 months ago

2.6.68

11 months ago

2.6.67

11 months ago

2.6.66

11 months ago

2.6.65

11 months ago

2.6.64

11 months ago

2.6.63

11 months ago

2.6.62

11 months ago

2.6.61

11 months ago

2.6.60

11 months ago

2.5.60

11 months ago

2.5.59

11 months ago

2.5.58

11 months ago

2.5.57

11 months ago

2.5.56

11 months ago

2.5.55

11 months ago

2.5.54

11 months ago

2.5.53

11 months ago

2.5.52

12 months ago

2.4.52

12 months ago

2.4.51

12 months ago

2.4.50

12 months ago

2.4.49

12 months ago

2.4.48

12 months ago

2.4.47

12 months ago

2.4.46

12 months ago

2.4.45

12 months ago

2.4.44

12 months ago

1.4.44

12 months ago

1.4.43

12 months ago

1.4.42

12 months ago

1.4.41

12 months ago

1.4.40

12 months ago

1.4.39

12 months ago

1.4.38

12 months ago

1.4.37

12 months ago

1.4.36

12 months ago

1.4.35

12 months ago

1.4.34

1 year ago

1.4.33

1 year ago

1.4.32

1 year ago

1.4.31

1 year ago

1.4.30

1 year ago

1.4.29

1 year ago

1.4.28

1 year ago

1.3.28

1 year ago

1.2.28

1 year ago

1.2.27

1 year ago

1.2.26

1 year ago

1.2.25

1 year ago

1.2.24

1 year ago

1.2.23

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

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