I wrote javascript-ipv6 for this very purpose. It currently powers v6decode.com.
Here's a short example of the API:
var address = new v6.Address("::ffff:7b2d:4359/64");
if (address.isValid()) {
// Do something if the address is valid
}
console.log(address.correctForm()); // "::ffff:7b2d:4359"
console.log(address.canonicalForm()); // "0000:0000:0000:0000:0000:ffff:7b2d:4359"
console.log(address.v4Form()); // "::ffff:123.45.67.89"
console.log(address.subnetMask); // "64"
console.log(address.possibleAddresses(96)); // "4,294,967,296"