@tour-kit/surveysUtilities
Utilities
Standalone scoring functions — calculateNPS, calculateCSAT, calculateCES — that work in React components, server actions, and analytics pipelines
Three pure functions for scoring survey responses. They have no React dependencies and can be used anywhere: in server actions, API routes, analytics ingestion pipelines, or inside React components.
Import
import { calculateNPS, calculateCSAT, calculateCES } from '@tour-kit/surveys';Available utilities
calculateNPS
Net Promoter Score from 0–10 ratings. Returns score, promoter/passive/detractor counts, and percentages.
calculateCSAT
Customer Satisfaction Score from ratings with a configurable positive threshold.
calculateCES
Customer Effort Score average from 1–7 ratings. Returns easy/difficult/neutral breakdown.
Within React components
Use useSurveyScoring to access these functions inside a SurveysProvider:
import { useSurveyScoring } from '@tour-kit/surveys';
function Results() {
const { getSurveyScore } = useSurveyScoring();
const result = getSurveyScore('nps-q1'); // auto-selects algorithm
}Outside React
import { calculateNPS } from '@tour-kit/surveys';
// In a server action or API route
const nps = calculateNPS([9, 10, 6, 7, 8, 10, 4]);
console.log(nps.score); // e.g. 14