-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
344 changed files
with
7,082 additions
and
5,460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
.* | ||
/playground | ||
node_modules | ||
!.eslintrc | ||
!.travis.yml | ||
!.prettierrc.yml | ||
!.gitignore | ||
!.github | ||
!.gitattributes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
experimentalTernaries: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import globals from "globals"; | ||
import js from "@eslint/js"; | ||
import mocha from "eslint-plugin-mocha"; | ||
import prettier from "eslint-plugin-prettier/recommended"; | ||
|
||
export default [ | ||
{ | ||
ignores: ["**/node_modules/", "docs/**", "extra/**"], | ||
}, | ||
{ | ||
languageOptions: { globals: { ...globals.node } }, | ||
}, | ||
js.configs.recommended, | ||
mocha.configs.flat.recommended, | ||
prettier, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,64 @@ | ||
|
||
// Dependencies | ||
import utils from '@nikitajs/core/utils'; | ||
import definitions from "./schema.json" with { type: "json" }; | ||
import utils from "@nikitajs/core/utils"; | ||
// Schema | ||
// import definitions from "./schema.json" with { type: "json" }; | ||
import { readFile } from "node:fs/promises"; | ||
const definitions = JSON.parse( | ||
await readFile(new URL("./schema.json", import.meta.url), "utf8"), | ||
); | ||
|
||
// Action | ||
export default { | ||
hooks: { | ||
on_action: function(action) { | ||
on_action: function (action) { | ||
action.handler = ((handler) => | ||
async function({config}) { | ||
async function ({ config }) { | ||
let result = await this.call({ | ||
$raw_output: true, | ||
$handler: handler | ||
$handler: handler, | ||
}); | ||
if (!Array.isArray(result)) { | ||
result = [result]; | ||
} | ||
if (!config.strict) { | ||
result = result.map(function(res) { | ||
result = result.map(function (res) { | ||
switch (typeof res) { | ||
case 'undefined': | ||
case "undefined": | ||
return false; | ||
case 'boolean': | ||
case "boolean": | ||
return !!res; | ||
case 'number': | ||
case "number": | ||
return !!res; | ||
case 'string': | ||
case "string": | ||
return !!res.length; | ||
case 'object': | ||
case "object": | ||
if (Buffer.isBuffer(res)) { | ||
return !!res.length; | ||
} else if (res === null) { | ||
return false; | ||
} else { | ||
return !!Object.keys(res).length; | ||
} | ||
case 'function': | ||
throw utils.error('NIKITA_ASSERT_INVALID_OUTPUT', ['assertion does not accept functions']); | ||
case "function": | ||
throw utils.error("NIKITA_ASSERT_INVALID_OUTPUT", [ | ||
"assertion does not accept functions", | ||
]); | ||
} | ||
}); | ||
} | ||
result = !result.some((res) => | ||
!config.not ? res !== true : res === true | ||
!config.not ? res !== true : res === true, | ||
); | ||
if (result !== true) { | ||
throw utils.error('NIKITA_ASSERT_UNTRUE', ['assertion did not validate,', `got ${JSON.stringify(result)}`]); | ||
throw utils.error("NIKITA_ASSERT_UNTRUE", [ | ||
"assertion did not validate,", | ||
`got ${JSON.stringify(result)}`, | ||
]); | ||
} | ||
} | ||
)(action.handler); | ||
} | ||
})(action.handler); | ||
}, | ||
}, | ||
metadata: { | ||
definitions: definitions | ||
} | ||
definitions: definitions, | ||
}, | ||
}; |
Oops, something went wrong.