Perform chemistry calculations and operations.
npm install chemicallab
console.log(element("O"))console.log(searchElement(atomicNumber : 1))name: string | 'unknown';
symbol: string | 'unknown';
atomicNumber: number | 'unknown';
atomicWeight: number | 'unknown';
period: number | 'unknown';
group: number | 'unknown';
phaseAtSTP: 'solid' | 'liquid' | 'gas' |'unknown'; // Standard Temperature and Pressure
meltingPoint?: number | 'unknown'; // in Kelvin
boilingPoint?: number| 'unknown'; // in Kelvin
electronegativity?: number | 'unknown'; // Pauling scale
density?: number | 'unknown';// g/cmÂł at STP
isRadioactive?: boolean | 'unknown';
electronConfiguration: string | 'unknown';
category: 'alkali metal' | 'alkaline earth metal' | 'transition metal' |
'post-transition metal' | 'metalloid' | 'nonmetal' |
'halogen' | 'noble gas' | 'lanthanide' | 'actinide' | 'unknown';// Example 1: H2 + O2 -> H2O
const reactants1 = ['H2', 'O2'];
const products1 = ['H2O'];
console.log(balanceChemicalEquation(reactants1, products1)); // Output: "2H2 + O2 -> 2H2O"
// Example 2: CH4 + O2 -> CO2 + H2O
const reactants2 = ['CH4', 'O2'];
const products2 = ['CO2', 'H2O'];
console.log(balanceChemicalEquation(reactants2, products2)); // Output: "CH4 + 2O2 -> CO2 + 2H2O"
// Example 3: Na + Cl2 -> NaCl
const reactants3 = ['Na', 'Cl2'];
const products3 = ['NaCl'];
console.log(balanceChemicalEquation(reactants3, products3)); // Output: "2Na + Cl2 -> 2NaCl"
// Example 4: Fe + O2 -> Fe2O3
const reactants4 = ['Fe', 'O2'];
const products4 = ['Fe2O3'];
console.log(balanceChemicalEquation(reactants4, products4)); // Output: "4Fe + 3O2 -> 2Fe2O3"
console.log(calculateElectronegativityDifference("Na", "O")); // Output: 1.24
console.log(calculateMolarMass("H2O")); // Output: 18.01528 (assuming atomic weights: H = 1.00794, O = 15.999)
console.log(calculateMolarMass("CO2")); // Output: 44.0095 (assuming atomic weights: C = 12.011, O = 15.999)
console.log(element("H")); // Output: { symbol: "H", name: "Hydrogen", atomicWeight: 1.00794, ... }
console.log(element("O")); // Output: { symbol: "O", name: "Oxygen", atomicWeight: 15.999, ... }
console.log(searchElement({ group: 1 })); // Output: All alkali metals (e.g., H, Li, Na, ...)
console.log(searchElement({ phaseAtSTP: "gas" })); // Output: All elements that are gases at STP (e.g., H, He, N, O, ...)
console.log(parseCompound("H2O")); // Output: Map { 'H' => 2, 'O' => 1 }
console.log(parseCompound("C6H12O6")); // Output: Map { 'C' => 6, 'H' => 12, 'O' => 6 }
console.log(getElementsInCompound("H2O")); // Output: ['H', 'O']
console.log(getElementsInCompound("C6H12O6")); // Output: ['C', 'H', 'O']
console.log(getElectronicConfiguration("H2O")); // Output: ['1s1', '1s1', '1s2 2s2 2p4']
console.log(getElectronicConfiguration("NaCl")); // Output: ['1s2 2s2 2p6 3s1', '1s2 2s2 2p6 3s2 3p5']
console.log(countElementsInCompounds(["H2O", "CO2"])); // Output: { H: 2, O: 3, C: 1 }
console.log(countElementsInCompounds(["CH4", "O2"])); // Output: { C: 1, H: 4, O: 2 }
console.log(getValenceElectrons(1, "H")); // Output: 1
console.log(getValenceElectrons(16, "O")); // Output: 6
console.log(calculateValenceElectrons({ H: 2, O: 1 })); // Output: 8 (2*1 + 6 = 8)
console.log(calculateValenceElectrons({ C: 1, H: 4 })); // Output: 8 (4*1 + 4 = 8)
console.log(getEmpiricalFormula("C6H12O6")); // Output: "CH2O"
console.log(getEmpiricalFormula("H2O2")); // Output: "HO"
console.log(getElementsByCategory("alkali metal")); // Output: All alkali metals (e.g., Li, Na, K, ...)
console.log(getElementsByCategory("noble gas")); // Output: All noble gases (e.g., He, Ne, Ar, ...)
console.log(getElementsByPhase("gas")); // Output: All gaseous elements at STP (e.g., H, He, N, O, ...)
console.log(getElementsByPhase("liquid")); // Output: All liquid elements at STP (e.g., Br, Hg)
console.log(calculateDensity(10, 5)); // Output: 2 (density = mass/volume = 10/5 = 2)
console.log(calculateMoles(18, 18.01528)); // Output: ~1 (moles of water)
console.log(calculateBondType("Na", "Cl")); // Output: "Ionic"
console.log(calculateBondType("H", "O")); // Output: "Polar Covalent"
console.log(calculateHalfLife(100, 50, 10)); // Output: 10 (half-life is 10 units of time)
console.log(calculatepH(0.01)); // Output: 2 (pH of 0.01M HCl)
console.log(calculatepH(0.001, false)); // Output: 11 (pH of 0.001M NaOH)
console.log(calculateIdealGasLaw(undefined, 2, 1, 300)); // Output: ~12.315 (pressure)
console.log(calculateIdealGasLaw(1, undefined, 1, 300)); // Output: ~24.63 (volume)
console.log(calculateEmpiricalFormulaFromPercentComposition({ H: 11.19, O: 88.81 })); // Output: "H2O"
console.log(calculatePercentComposition("H2O")); // Output: { H: ~11.19, O: ~88.81 }
console.log(calculateConcentration(2, 0.5)); // Output: 4 (Molarity = moles/volume = 2/0.5 = 4M)console.log(generateIUPACName("CH4")); given output -> "methane" expected output -> "methane"
console.log(generateIUPACName("C2H6")); given output -> "ethane" expected output -> "ethane"
console.log(generateIUPACName("C3H8")); given output -> "propane" expected output -> "propane"
console.log(generateIUPACName("C4H10")); given output -> "butane" expected output -> "butane"
console.log(generateIUPACName("CH3OH")); given output -> "methane" expected output -> "methanol"
console.log(generateIUPACName("CH3CH2OH")); given output -> "ethane" expected output -> "ethanol"
console.log(generateIUPACName("CH3CH2CH3")); given output -> "propane" expected output -> "propane"
console.log(generateIUPACName("CH3CH2CH2OH")); given output -> "propane" expected output -> "2-hydroxypropane"
console.log(generateIUPACName("CH3CH2Cl")); given output -> "1-chloro-ethane" expected output -> "1-chloroethane"
console.log(generateIUPACName("CH3CHClCH3")); given output -> "2-chloro-propane" expected output -> "2-chloropropane"
console.log(generateIUPACName("CH3CHClCH2Cl")); given output -> "1,2-chloro-propane" expected output -> "1,2-dichloropropane"
console.log(generateIUPACName("CH3CH2CH2NH2")); given output -> "propane" expected output -> "1-aminopropane"
console.log(generateIUPACName("CH3CHCH3CH3")); given output -> "butane" expected output -> "2-methylbutane"
console.log(generateIUPACName("CH3CHOHCH3")); given output -> "propane" expected output -> "2-hydroxypropane"
console.log(generateIUPACName("CH3CBrClCH3")); given output -> "2-bromo-2-chloro-propane" expected output -> "2-bromo-2-chloropropane"
console.log(generateIUPACName("CH3CHNO2CH3")); given output -> "propane" expected output -> "2-nitropropane"
console.log(generateIUPACName("CH3CH2CH2CH2OH")); given output -> "butane" expected output -> "1-hydroxybutane"
console.log(generateIUPACName("CH3CHBrCH2CH3")); given output -> "2-bromo-butane" expected output -> "2-bromobutane"
console.log(generateIUPACName("CH3CH2CHClCH3")); given output -> expected output -> "2-chlorobutane"
console.log(generateIUPACName("CH3CH2CHOHCH3")); given output -> "2-chloro-butane" expected output -> "2-hydroxybutane"
console.log(generateIUPACName("CH3CH2CH2CH2NH2")); given output -> "butane" expected output -> "1-aminobutane"
console.log(generateIUPACName("CH3CNO2CH2CH3")); given output -> "butane" expected output -> "2-nitrobutane"