2.3.83 • Published 1 year ago

@zitterorg/eligendi-eligendi-deserunt v2.3.83

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

Json Joi

Build Status Node version required Latest Stable Version

Json-Joi is a powerfull TypeScript module that builds on top of Joi module. Converts Joi objects to json and vice versa, makes Joi objects from json.

From Joi description: "The most powerful schema description language and data validator for JavaScript."

See Joi API for documentation and api.

Json-Joi supports almost entire Joi API!

Installation

npm install @zitterorg/eligendi-eligendi-deserunt

Usage

import Joi, {fromJson, toJson, Schema} from '@zitterorg/eligendi-eligendi-deserunt';

const json: Schema = {
  type: "object",
  properties: {
    a: {
      type: "number",
      min: 100,
      max: 1000,
      required: true
    }
  }
};

// fromJson(json) is equal to following

const joi = Joi.object({
  a: Joi.number().min(100).max(1000).required()
});

// VALID
assert.deepEqual(toJson(joi), toJson(fromJson(json)));

Joi Reference & Functions

{
  a: {
    type: "number"
  },
  b: {
    type: "number",
    min: {
      $ref: "a",
      adjust: "value => value + 1"
    }
  }
}

// where adjust is a stringed function

// is equal to
Joi.object({
  a: Joi.number(),
  b: Joi.number.min(Joi.ref("a", {
    adjust: value => value + 1
  }))
})

Joi RegExp

let json: ObjectSchema = {
  type: "object",
  properties: {
    a: {
      type: "string",
      pattern: "/a/"
    },
    b: {
      type: "string",
      regex: {$regex: "/a/", flags: "i"}
    },
    c: {
      type: "string",
      regex: {pattern: {$regex: "/a/"}}
    }
  }
};

const converted = (toJson(fromJson(json)) as any);

assert.equal(converted.properties?.a?.pattern?.regex?.$regex, '\\/a\\/');
assert.equal(converted.properties?.b?.pattern?.regex?.$regex, '\\/a\\/');
assert.equal(converted.properties?.b?.pattern?.regex?.flags, 'i');
assert.equal(converted.properties?.c?.pattern?.regex?.$regex, '\\/a\\/');

Joi Replace

{
  type: "string",
  replace: {find: {$regex: "a", flags: "gi"}, replace: "b"}
}

// is equal to
Joi.string().replace(/a/gi, "b")

{
  type: "string",
  replace: [
    {find: {$regex: "a", flags: "gi"}, replace: "b"},
    {find: "a", replace: "b"}
  ]
}

// is equal to
Joi.string().replace(/a/gi, "b").replace("a", "b")
inferenceinternaltextenumerable@@toStringTagFloat64ArrayspinnersmimedragfunctionreduxlockfilepipeefficienttrimfindupserializewordbreakshamESnextclass-validatorpushgetintrinsichookformcoercibleawaitbusytypeofformattingmakepackage managerjsoninternal slotnodespinnerequalityiterationphoneuninstallparsedotenvreuseECMAScript 2015apollobannerdeep-copyboundincludesnameslintshared.envchromeObjecthigher-orderpackagehardlinkscodesopenstouchkarmasearchslicearraybuffercall-bindurlsafepolyfillindicatorcensoroutputoptimizersortemitstatelesssesduplexremoveterminalBigUint64ArraytoobjectlistenerswalkRegExp#flagsfilterhashprivate datastreamentriessortedstyleguideidentifiersownUint16Arrayxtermglobprefixansicompilermapreducenameworkspace:*startnativettyshellclientbluebirdistanbulECMAScript 2022configmoduleendpointmatchAllbindappassertsetfunctionalsyntaxfsregular expressionscompareCSSjsspeci18nBigInt64Arraymoveformstylesflagcloudformationemrfullwidthpromisekeypropertiesstringifycliwhatwgloadingcloudwatchserialization256apilazydescriptioninspectstreams2WeakSetMapObject.getPrototypeOfconcatMapworkertypaniones2018tostringtagcharacterES2020asynccall-boundreadablestreamloggerform-validationsymbolsrdsrmpackage.jsonagentmetadatareact-hook-formexecutableES2023defaultavaextendrateWeakMapchannelArray.prototype.filterbyteOffsetdescriptorssettingspluginerrorautoscaling_.extendstreamslook-upstyled-components[[Prototype]]prunefulltelephoneprotobufl10nruntimehas-owntaskStreamTypeScriptdefinePropertycallbindreacticuES8bytefolderECMAScript 2016buffersajvnodejsbufferthreecolorwalkingdatasameValueZerowafconcatgetterUint32Arrayminimalmerges3toStringTagjestvalidationcurlvalidateshimperformantjasmineFunction.prototype.namesimpledbschemaimportexporthaspathrm -rftimewaitgroupByfastcopyidleiterateArrayBuffer#slicequerystringtoArrayJSON-SchemaresolvefigletsuperstructproxyfindLastspringinupprototypedires7core-jsdebuggerflagsargvtrimEndmkdirworkflowrmdirmkdirpsyntaxerrorutilitymruWebSocketredactassignaccessornegativemapPromisecolorsunicodeurlsES7JSONthroatpostcsscryptoglaciercode pointsArray.prototype.findLastIndexnpmreact-hookslimitcloudsearchfindLastIndexvestobjreal-timeArrayconfigurabletypedObject.assignesisConcatSpreadableInt8ArrayvariablesUint8Arrayscheme-validationzerodayjsconsumees-shims-0react-testing-libraryECMAScript 5trimLeftgetroutingimmutablebrowserlisteslintpluginshrinkwrapdynamodbRFC-6455URLSearchParamsmochaperformancevisualkeysWebSocketsdeletesymbolfastclonehttpfastifyformatxhrflattenwritabletoolkitgesturesStyleSheettestingimmerfind-uprequireoptiontslibobjectpopmotionregexemojieventsguidgetOwnPropertyDescriptoriteratorArray.prototype.containsgroupredux-toolkiteverydom-testing-libraryMicrosoftsometoSortedprocessjsonpatheslint-plugingetopthttpsstylequeueMicrotaskconsoleES2021sqsvaluereact posefixed-widthexeES2015es2017containsconvertAsyncIteratordomyupchromiumECMAScript 2019TypedArraylaunchObject.definePropertyinstallereslintweakmaprequestlimitedspeedexpresscommanderdataView__proto__ES5escapespawnslotes5
2.3.83

1 year ago

2.3.79

1 year ago

2.3.80

1 year ago

2.3.82

1 year ago

2.3.81

1 year ago

2.2.79

1 year ago

2.2.78

1 year ago

2.2.77

1 year ago

2.2.75

1 year ago

2.2.76

1 year ago

2.2.73

1 year ago

2.2.74

1 year ago

2.2.71

1 year ago

2.2.72

1 year ago

2.1.49

1 year ago

2.2.59

1 year ago

2.1.47

1 year ago

2.1.48

1 year ago

2.1.45

1 year ago

2.2.58

1 year ago

2.1.46

1 year ago

2.1.43

1 year ago

2.1.44

1 year ago

2.1.41

1 year ago

2.1.42

1 year ago

2.1.40

1 year ago

2.1.58

1 year ago

2.2.68

1 year ago

2.1.56

1 year ago

2.2.69

1 year ago

2.1.57

1 year ago

2.2.66

1 year ago

2.1.54

1 year ago

2.2.67

1 year ago

2.1.55

1 year ago

2.2.64

1 year ago

2.1.52

1 year ago

2.2.65

1 year ago

2.1.53

1 year ago

2.2.62

1 year ago

2.1.50

1 year ago

2.2.63

1 year ago

2.1.51

1 year ago

2.2.60

1 year ago

2.2.61

1 year ago

2.2.70

1 year ago

2.1.38

1 year ago

2.1.39

1 year ago

2.1.36

1 year ago

2.1.37

1 year ago

2.1.34

1 year ago

2.1.35

1 year ago

2.1.33

1 year ago

2.1.32

1 year ago

2.1.28

1 year ago

2.1.29

1 year ago

2.1.30

1 year ago

2.1.31

1 year ago

2.1.27

1 year ago

2.1.25

1 year ago

2.1.26

1 year ago

2.1.18

1 year ago

2.1.19

1 year ago

2.1.23

1 year ago

2.1.24

1 year ago

2.1.21

1 year ago

2.1.22

1 year ago

2.1.20

1 year ago

2.1.16

1 year ago

2.1.17

1 year ago

2.1.14

1 year ago

2.1.15

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.9

1 year ago

2.1.10

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

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