UNPKG

usps-webtools-promise

Version:

API wrapper for the USPS Web-Tools, with Promises!

35 lines (34 loc) 904 B
export default (value) => { let string = value.replaceAll(/[^\W_][^\s-]* */g, (txt) => txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase()); const lowers = [ "A", "An", "The", "And", "But", "Or", "For", "Nor", "As", "At", "By", "For", "From", "In", "Into", "Near", "Of", "On", "Onto", "To", "With", ]; for (const [index] of Object.keys(lowers).entries()) { string = string.replaceAll(new RegExp(`\\s${lowers[index]}\\s`, "g"), (txt) => txt.toLowerCase()); } const uppers = ["Ne", "Nw", "Po", "Se", "Sw"]; for (const [index] of Object.keys(uppers).entries()) { string = string.replaceAll(new RegExp(`\\b${uppers[index]}\\b`, "g"), (txt) => txt.toUpperCase()); } return string; };