UNPKG

fieldify

Version:

Fieldify object manipulation & validator

59 lines (51 loc) 2.12 kB
const ftURLDecode = async (data) => { try { data.result = new URL(data.value); // Verifies if the provided value is a valid URL } catch (e) { data.error = e.message; // If an error occurs, store the error message in the 'error' property of the 'data' object return; // Exit the function } }; const ftURLVerify = async (data) => { if(!data.value || data.value.length === 0) return try { new URL(data.value); // Verifies if the provided value is a valid URL data.result = data.value } catch (e) { data.error = e.message; // If an error occurs, store the error message in the 'error' property of the 'data' object return; // Exit the function } }; const ftURLEncode = async (data) => { if (data.value instanceof URL) data.result = data.value.href; // Convert the URL object to a string representation else data.result = data.value }; const ftURLSanitize = async (controler) => { // TODO: Implement URL sanitization logic }; const ftURLSchematizer = async (controler) => { // TODO: Implement URL schematization logic }; const ftURLConfig = { // TODO: // protocols: { // $doc: 'Specify minimum value', // $required: false, // $type: 'URL' // }, }; /** * ftURL module. */ const ftURL = { encode: ftURLEncode, // Expose the ftURLEncode function as part of the ftURL module's public interface decode: ftURLDecode, // Expose the ftURLVerify function as part of the ftURL module's public interface verify: ftURLVerify, // Expose the ftURLVerify function as part of the ftURL module's public interface sanitize: ftURLSanitize, // Expose the ftURLSanitize function as part of the ftURL module's public interface schematizer: ftURLSchematizer, // Expose the ftURLSchematizer function as part of the ftURL module's public interface configuration: ftURLConfig, // Expose the ftURLConfig object as part of the ftURL module's public interface }; module.exports = ftURL; // Export the ftURL module for use in other parts of the application