generated from openpeeps/pistachio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: George Lemon <georgelemon@protonmail.com>
- Loading branch information
1 parent
7ce9c54
commit 0ce88e2
Showing
7 changed files
with
93 additions
and
47 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,27 +1,72 @@ | ||
import std/[macros, os, strutils] | ||
|
||
macro importFilters() = | ||
let filtersPath = currentSourcePath().parentDir / "valido" | ||
var | ||
filters = newTree(nnkBracket) | ||
procs = newTree(nnkStmtList) | ||
exports = newTree(nnkExportStmt) | ||
for filter in walkDir(filtersPath): | ||
if not filter.path.endsWith(".nim"): | ||
continue | ||
let filterName = filter.path.extractFilename()[0 .. ^5] | ||
filters.add ident filterName | ||
exports.add ident filterName | ||
result = newStmtList() | ||
result.add( | ||
nnkImportStmt.newTree( | ||
nnkInfix.newTree( | ||
ident "/", | ||
ident "valido", | ||
filters | ||
) | ||
), | ||
exports | ||
) | ||
|
||
importFilters() | ||
when defined napibuild: | ||
import denim | ||
import pkg/valido/[base32, base58, base64, domain, email, ean, ip, md5] | ||
|
||
const errident = "Valido" | ||
|
||
init proc(module: Module) = | ||
module.registerFn(1, "isEmail"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isEmail(args[0].getStr) | ||
|
||
module.registerFn(2, "isIP4"): | ||
echo args.len | ||
if Env.expect(args, errident, ("input", napi_string), ("?allowLoopback", napi_boolean)): | ||
return %* isIP4(args[0].getStr, args[1].getBool) | ||
|
||
module.registerFn(1, "isDomain"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isDomain(args[0].getStr) | ||
|
||
module.registerFn(1, "isBase32"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isBase32(args[0].getStr) | ||
|
||
module.registerFn(1, "isBase58"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isBase58(args[0].getStr) | ||
|
||
module.registerFn(1, "isMD5"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isMD5(args[0].getStr) | ||
|
||
module.registerFn(1, "isEAN13"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isEAN13(args[0].getStr) | ||
|
||
module.registerFn(1, "isEAN8"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isEAN8(args[0].getStr) | ||
|
||
module.registerFn(1, "isEAN"): | ||
if Env.expect(args, errident, ("input", napi_string)): | ||
return %* isEAN(args[0].getStr).status | ||
|
||
else: | ||
macro importFilters() = | ||
let filtersPath = currentSourcePath().parentDir / "valido" | ||
var | ||
filters = newTree(nnkBracket) | ||
procs = newTree(nnkStmtList) | ||
exports = newTree(nnkExportStmt) | ||
for filter in walkDir(filtersPath): | ||
if not filter.path.endsWith(".nim"): | ||
continue | ||
let filterName = filter.path.extractFilename()[0 .. ^5] | ||
filters.add ident filterName | ||
exports.add ident filterName | ||
result = newStmtList() | ||
result.add( | ||
nnkImportStmt.newTree( | ||
nnkInfix.newTree( | ||
ident "/", | ||
ident "valido", | ||
filters | ||
) | ||
), | ||
exports | ||
) | ||
|
||
importFilters() |
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
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