mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			590 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			590 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
export const stripTrailingSlash = ({ URL }) => {
 | 
						|
  return URL.replace(/\/$/, '');
 | 
						|
};
 | 
						|
 | 
						|
// Format all campaigns
 | 
						|
export const formatCampaigns = ({ campaigns }) => {
 | 
						|
  return campaigns.map(item => {
 | 
						|
    return {
 | 
						|
      id: item.id,
 | 
						|
      timeOnPage: item?.trigger_rules?.time_on_page,
 | 
						|
      url: item?.trigger_rules?.url,
 | 
						|
    };
 | 
						|
  });
 | 
						|
};
 | 
						|
 | 
						|
// Find all campaigns that matches the current URL
 | 
						|
export const filterCampaigns = ({ campaigns, currentURL }) => {
 | 
						|
  return campaigns.filter(
 | 
						|
    item =>
 | 
						|
      stripTrailingSlash({ URL: item.url }) ===
 | 
						|
      stripTrailingSlash({ URL: currentURL })
 | 
						|
  );
 | 
						|
};
 |