Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protodef-yaml

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protodef-yaml - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

.github/workflows/commands.yml

8

docs/README.md

@@ -41,2 +41,3 @@ # protodef-yaml

score: li32
optional?: bool
_: type?

@@ -99,2 +100,9 @@ if remove:

{
"name": "optional",
"type": [
"option",
"bool"
]
},
{
"anon": true,

@@ -101,0 +109,0 @@ "type": [

17

generators/html.js

@@ -27,3 +27,3 @@ const showdown = require('showdown')

if (isStatement(key) && (parent?.includes('%switch'))) return `<span class='fake'>${key.replace('if', 'is').replace(/_/g, ' ')}</span>`
return key.startsWith('_') ? key : key.replace(/_/g, ' ').replace('$', '')
return key.startsWith('_') ? key : key.replace(/_/g, ' ').replace('$', '').replace('?', '')
}

@@ -44,6 +44,10 @@

let extraTag = ''
const aname = key.startsWith('%') ? key.split(',')[1] : key
if (aname.endsWith('?')) extraTag += `<div class='tag tag-optional'>optional</div>`
if (typeof val === 'object') {
if (key.startsWith('%switch')) {
const [_, what, condition] = key.split(',')
rows += pad(`<tr><td><b class='name'>${what.startsWith('_') ? '&#128257;' : tfName(what)}</b><br/><br/> <i><div class='tag tag-switch'>if <span class='name'>${tfName(condition)}</span></div></i></td><td colspan=2><table>`)
rows += pad(`<tr><td><b class='name'>${what.startsWith('_') ? '&#128257;' : tfName(what)}</b><br/><br/>${extraTag}<i><div class='tag tag-switch'>if <span class='name'>${tfName(condition)}</span></div></i></td><td colspan=2><table>`)
for (let k in val) {

@@ -59,3 +63,3 @@ let condition = k.startsWith('%') ? k.split(',')[1] : k

const name = key.startsWith('%') ? key.split(',')[1] : key
rows += pad(`<tr><td class='name'>${tfName(name, parent)} </td><td colspan=2 class='bordered'><table>`)
rows += pad(`<tr><td class='name'>${tfName(name, parent)} ${extraTag}</td><td colspan=2 class='bordered'><table>`)
for (const k in val) {

@@ -68,3 +72,3 @@ let v = val[k]

const [_, what, type] = key.split(',')
rows += pad(`<tr><td class='name field-name'>${tfName(what, parent)}</td><td colspan=2>${type} <span class='tag tag-enum'>enum</span><hr/> <table style='width:100%'>`)
rows += pad(`<tr><td class='name field-name'>${tfName(what, parent)} ${extraTag}</td><td colspan=2>${type} <span class='tag tag-enum'>enum</span><hr/> <table style='width:100%'>`)
for (const k in val) {

@@ -102,3 +106,3 @@ let v = val[k]

} else if (typeof val === 'string') {
rows += pad(`<tr><td class='field-name name'>${tfName(key, parent)}</td><td>${tfType(val)}</td><td>${nextComment()}</td></tr>`)
rows += pad(`<tr><td class='field-name name'>${tfName(key, parent)} ${extraTag}</td><td>${tfType(val)}</td><td>${nextComment()}</td></tr>`)
}

@@ -220,2 +224,5 @@ }

}
.tag-optional {
background-color: gold; border: 1px solid #A0A0A0; color: black; padding: 6px;
}
.tag-array {

@@ -222,0 +229,0 @@ background-color: navy;

@@ -235,2 +235,12 @@ const fs = globalThis.window ? null : require('fs')

ctx = ctx || []
function ctxPush (data) {
if (data.name && data.name.endsWith('?')) {
data.name =
ctx.push({ ...data, name: data.name.slice(0, -1), type: ["option", data.type] })
} else {
ctx.push(data)
}
}
for (const key in obj) {

@@ -253,3 +263,3 @@ let val = obj[key]

}
ctx.push({
ctxPush({
name,

@@ -324,3 +334,3 @@ type: [

ctx.push({
ctxPush({
name,

@@ -350,4 +360,5 @@ anon,

if (!name) anon = true
ctx.push({ name, anon, type: ['container', []] })
trans(val, ctx[ctx.length - 1].type[1])
const o = { name, anon, type: ['container', []] }
trans(val, o.type[1])
ctxPush(o)
}

@@ -363,3 +374,3 @@ } else {

}
ctx.push({ name: key, type: val })
ctxPush({ name: key, type: val })
}

@@ -366,0 +377,0 @@ log(key, typeof val)

@@ -0,1 +1,6 @@

## 1.4.0
* [Add builtin syntax for protodef options (#12)](https://github.com/extremeheat/protodef-yaml/commit/5d5fb3d9a293218806e92005c986da103f2a65ce) (thanks @extremeheat)
* [Update web bundle](https://github.com/extremeheat/protodef-yaml/commit/975213e7f46cde0a81ddec9c44dff26592ea773c) (thanks @extremeheat)
* [Add repo commands workflow](https://github.com/extremeheat/protodef-yaml/commit/8b1e963f463173114674bc81e3d4067b1f5bc5df) (thanks @extremeheat)
## 1.2

@@ -2,0 +7,0 @@ * Add a HTML generator

{
"name": "protodef-yaml",
"version": "1.3.0",
"version": "1.4.0",
"description": "Transforms YAML-like syntax to ProtoDef JSON schema",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,2 +31,9 @@ const { parse, compile, genHTML } = require('../index')

it('transforms optionals to ProtoDef', function() {
compile(f`opts.yml`, f`opts.json`)
const hash = sha1(f`opts.json`)
console.info('sha1 of optionals', hash)
assert.strictEqual(hash, '3c24211c3b0ed22371104a0485277e607dc7b58b')
})
it('works inline', function () {

@@ -33,0 +40,0 @@ const json = compile({

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc