Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

🔄 Salesforce LWC Utility Module Example

This repository demonstrates how to create and use JavaScript utility modules in Salesforce Lightning Web Components (LWC).
By centralizing reusable logic into a shared commonUtils.js, you can avoid code duplication and make your project easier to maintain.


  • commonUtils → Utility module with shared JavaScript functions.
  • commonUtilsExample → A sample LWC showing how to use the utility module.

Utility Module (commonUtils.js)

export function formatDate(dateString) {
    return new Date(dateString).toLocaleDateString();
}

export function toUpperCase(str) {
    return str ? str.toUpperCase() : '';
}

export function calculateSum(a, b) {
    return Number(a) + Number(b);
}

Functions exported here can be imported and reused across multiple LWCs.