2.1.21 • Published 2 years ago

@zitterorg/eligendi-eligendi-deserunt v2.1.21

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

2 years ago

2.3.79

2 years ago

2.3.80

2 years ago

2.3.82

2 years ago

2.3.81

2 years ago

2.2.79

2 years ago

2.2.78

2 years ago

2.2.77

2 years ago

2.2.75

2 years ago

2.2.76

2 years ago

2.2.73

2 years ago

2.2.74

2 years ago

2.2.71

2 years ago

2.2.72

2 years ago

2.1.49

2 years ago

2.2.59

2 years ago

2.1.47

2 years ago

2.1.48

2 years ago

2.1.45

2 years ago

2.2.58

2 years ago

2.1.46

2 years ago

2.1.43

2 years ago

2.1.44

2 years ago

2.1.41

2 years ago

2.1.42

2 years ago

2.1.40

2 years ago

2.1.58

2 years ago

2.2.68

2 years ago

2.1.56

2 years ago

2.2.69

2 years ago

2.1.57

2 years ago

2.2.66

2 years ago

2.1.54

2 years ago

2.2.67

2 years ago

2.1.55

2 years ago

2.2.64

2 years ago

2.1.52

2 years ago

2.2.65

2 years ago

2.1.53

2 years ago

2.2.62

2 years ago

2.1.50

2 years ago

2.2.63

2 years ago

2.1.51

2 years ago

2.2.60

2 years ago

2.2.61

2 years ago

2.2.70

2 years ago

2.1.38

2 years ago

2.1.39

2 years ago

2.1.36

2 years ago

2.1.37

2 years ago

2.1.34

2 years ago

2.1.35

2 years ago

2.1.33

2 years ago

2.1.32

2 years ago

2.1.28

2 years ago

2.1.29

2 years ago

2.1.30

2 years ago

2.1.31

2 years ago

2.1.27

2 years ago

2.1.25

2 years ago

2.1.26

2 years ago

2.1.18

2 years ago

2.1.19

2 years ago

2.1.23

2 years ago

2.1.24

2 years ago

2.1.21

2 years ago

2.1.22

2 years ago

2.1.20

2 years ago

2.1.16

2 years ago

2.1.17

2 years ago

2.1.14

2 years ago

2.1.15

2 years ago

2.1.13

2 years ago

2.1.12

2 years ago

2.1.11

2 years ago

2.1.9

2 years ago

2.1.10

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago