@hashcoop/loloyal-coupon-resolver
v0.1.10
Published
Loloyal coupon name resolve
Keywords
Readme
@hashcoop/loloyal-coupon-resolver
开发
本地调试
pnpm dev发布
pnpm publishAPI
npm install @hashcoop/loloyal-coupon-resolver优惠券相关类型
type CouponTemplateType = "general" | "refer" | "vip";
enum COUPON_TYPES {
Fixed = 1,
Percentage = 2,
Shipping = 3,
Increments = 4,
Product = 5,
PosAmount = 6,
PosPercentage = 7,
}
enum REFERRAL_REWARD_TYPES {
Amount = 1,
Percentage = 2,
Points = 3,
Shipping = 4,
Product = 5,
}CouponNameVariablesMap
优惠券名称占位符变量
enum CouponNameVariablesMap {
points = "points",
discount_amount = "discount_amount",
fixed_discount = "fixed_discount",
percentage_discount = "percentage_discount",
}getCouponMapByTemplateType
获取优惠券占位符变量与字段映射对象
const featureTypeFunctionMap = getCouponMapByTemplateType('general')getResolvedCouponName
解析单个优惠券名称
const name = getResolvedCouponName({
currencySymbol: '$';
couponTemplateType: 'general';
couponType: 1;
amount: '10000';
points: 100;
name: '花费{{points}}兑换{{fixed_discount}}优惠券';
localeCode: 'zh-CN';
})
console.log(name) // spending 100 points to get 00 off coupongetResolvedCouponName
解析优惠券名称列表
const originNames = [
'花费 {{points}} 兑换 {{fixed_discount}} 优惠券',
'spending {{points}} points to get {{fixed_discount}} off coupon'
],
const discountFunction = featureTypeFunctionMap[COUPON_TYPES.Fixed]
const discountParams: GetVarMapParams = {
amount: '10000',
points: 100,
}
const names = originNames.map((item) => item.value.value)
const resolvedNames = getResolvedCouponNameList(
names,
discountFunction(discountParams),
)
