lib:strict

none

Author
rssa_romeo
Daily installs
0
Total installs
2
Ratings
0 0 0
Version
2
Created
2024-04-10
Updated
2024-04-19
License
GPLv3
Applies to
All sites

example:

with (loadlib("strict")) {
      obj.forEach((obj) =>
        testformat(obj, {
          text: condfunc(({ key }) =>
            setformat({ type: key ? ["string", "none"] : ["string"] })
          ),
          key: condfunc(({ text }) =>
            setformat({ type: text ? ["string", "none"] : ["string"] })
          ),
          type: setformat({
            value: [
              "button",
              "boolean",
              "text",
              "number",
              "key",
              "none",
              "select",
              "range",
              "color",
              "array",
            ],
          }),
          forcelower: condfunc((obj) => {
            return setformat({
              value: ["text", "key"].includes(obj.type)
                ? [true, false, undefined]
                : [undefined],
            })
          }),
          tab: optional(setformat({ type: "number" })),
          innerstyle: optional(
            setformat(
              {},
              { allowextras: true, extrasformat: { type: ["string"] } }
            )
          ),
          outerstyle: optional(
            setformat(
              {},
              { allowextras: true, extrasformat: { type: ["string"] } }
            )
          ),
          buttontext: condfunc((obj) => {
            return setformat({
              type: obj.type == "button" ? ["string"] : ["none"],
            })
          }),
          hint: optional(setformat({ type: ["string"] })),
          onclick: condfunc((obj) => {
            return setformat({
              type:
                obj.type == "button" ? ["function", "asyncfunction"] : ["none"],
            })
          }),
          options: condfunc((obj) => {
            return setformat({
              type: obj.type == "select" ? ["array"] : ["none"],
            })
          }),
          oncontextmenu: condfunc((obj) => {
            return setformat({
              type:
                obj.type == "button" ? ["function", "asyncfunction"] : ["none"],
            })
          }),
          min: condfunc((obj) => {
            return setformat({
              type: obj.type == "range" ? ["number"] : ["none"],
            })
          }),
          max: condfunc((obj) => {
            return setformat({
              type: obj.type == "range" ? ["number"] : ["none"],
            })
          }),
          hinttype: condfunc((obj) => {
            return setformat({
              value: "hint" in obj ? ["text", "html"] : [undefined],
            })
          }),
          allowmodifiers: condfunc((obj) => {
            return setformat({
              value: obj.type == "key" ? [true, false] : [undefined],
            })
          }),
          keyreturntype: condfunc((obj) => {
            return setformat({
              value: obj.type == "key" ? ["object", "string"] : [undefined],
            })
          }),
        })
      )
    }

example used in https://greasyfork.org/en/scripts/492112-options-menu-lib-menu