UNPKG

nv-data-selection

Version:

nv-data-selection ============ - nv-data-selection ,nest selection - multi, radio,value,validator - notifier callback

51 lines (39 loc) 1.28 kB
const url = require("url"); const {is_int_str} = require("nv-string-basic"); const {is_int,is_str} = require("nv-facutil-basic"); const IPV4_ADDR_REGEX = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; const is_ipv4_addr = (s)=> is_str(s) && s.match(IPV4_ADDR_REGEX)!==null; const is_port =(port)=> { if(is_int(port) || (is_str(port) && is_int_str(port))) { port = Number(port); return(port>=1 && port<= 65535) } else { return(false) } } const is_url_abs_path = (s)=>{ if(is_str(s)) { let d = url.parse(s); return(d.protocol===null && d.host===null && d.path[0]==='/'); } else { return(false) } } const is_url_abs_pathname = (s)=>{ if(is_str(s)) { let d = url.parse(s); return(d.protocol===null && d.host===null && d.path[0]==='/' && d.search===''); } else { return(false) } } const is_tru_str = (s)=> is_str(s) && s.toLowerCase()==='true'; const is_fls_str = (s)=> is_str(s) && s.toLowerCase()==='false'; module.exports = { is_ipv4_addr, is_port, is_url_abs_path, is_url_abs_pathname, is_tru_str, is_fls_str }