Skip to content

Commit f0cb6f8

Browse files
committed
Remove lodash, add capitalizefirst, misc
1 parent 4aea92e commit f0cb6f8

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
},
3737
"dependencies": {
3838
"@phensley/timezone": "~1.2.17",
39-
"lodash": "^4.17.21",
4039
"utf8": "^3.0.0"
4140
},
4241
"peerDependencies": {
@@ -48,7 +47,6 @@
4847
"@rollup/plugin-json": "^4.0.3",
4948
"@rollup/plugin-node-resolve": "^7.1.3",
5049
"@types/jest": "^29.5.10",
51-
"@types/lodash": "^4.17.13",
5250
"@types/node": "^20.10.0",
5351
"@types/utf8": "^3.0.3",
5452
"beautify-benchmark": "^0.2.4",

src/plugins/formatters.commerce.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import capitalize from 'lodash/capitalize';
21
import { Context } from '../context';
32
import { ProductType } from './enums';
43
import { Node } from '../node';
@@ -245,12 +244,12 @@ export class ProductPriceFormatter extends Formatter {
245244
// This string needs to match the correct translation template in v6 products-2.0-en-US.json.
246245
let localizedStringKey = 'productPrice__' +
247246
`${hasMultiplePrices ? 'multiplePrices' : 'singlePrice'}__` +
248-
`${billingPeriodValue === 1 ? '1' : 'n'}${capitalize(billingPeriodUnit)}ly__`;
247+
`${billingPeriodValue === 1 ? '1' : 'n'}${stringutil.capitalizeFirst(billingPeriodUnit)}ly__`;
249248

250249
if (durationValue == 0) {
251250
localizedStringKey += 'indefinite';
252251
} else {
253-
localizedStringKey += `limited__${durationValue === 1 ? '1' : 'n'}${capitalize(durationUnit)}s`;
252+
localizedStringKey += `limited__${durationValue === 1 ? '1' : 'n'}${stringutil.capitalizeFirst(durationUnit)}s`;
254253
}
255254

256255
const localizedStringNode = ctx.resolve(['localizedStrings', localizedStringKey]);

src/plugins/util.commerce.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export const getAmountFromMoneyNode = (moneyNode?: Node) => {
4444

4545
export const getCurrencyFromMoneyNode = (moneyNode: Node): CurrencyType => {
4646
const currencyNode = moneyNode.path(['currency']);
47-
const currency = !currencyNode.isMissing() ?
48-
currencyNode.asString().trim() :
49-
DEFAULT_MONEY_NODE.path(['currency']).asString();
47+
const currency = !currencyNode.isMissing() ? currencyNode.asString().trim() : DEFAULT_MONEY_NODE.path(['currency']).asString();
5048

5149
return currency as CurrencyType;
5250
};
@@ -60,7 +58,7 @@ export const getMoneyString = (moneyNode: Node, args: string[], ctx: Context): s
6058
if (useCLDRMode(ctx)) {
6159
const amount = getAmountFromMoneyNode(moneyNode);
6260
const currencyCode = getCurrencyFromMoneyNode(moneyNode);
63-
61+
6462
return ctx.cldr?.Numbers.formatCurrency(amount, currencyCode, currencyOptions(args)) ?? '';
6563
} else {
6664
const legacyAmount = getLegacyPriceFromMoneyNode(moneyNode);
@@ -78,15 +76,13 @@ export const getSubscriptionMoneyFromFirstPricingOptions = (pricingOptions: Node
7876

7977
const node = pricingOptions.get(0);
8078

81-
return isTruthy(node.path(['onSale']))
82-
? node.path(['salePriceMoney'])
83-
: node.path(['priceMoney']);
79+
return isTruthy(node.path(['onSale'])) ? node.path(['salePriceMoney']) : node.path(['priceMoney']);
8480
};
8581

8682
export const getPricingOptionsAmongLowestVariant = (item: Node): Node | null => {
8783
const productType = getProductType(item);
8884
const structuredContent = item.path(['structuredContent']);
89-
85+
9086
switch (productType) {
9187
case ProductType.PHYSICAL:
9288
case ProductType.SERVICE:
@@ -96,9 +92,7 @@ export const getPricingOptionsAmongLowestVariant = (item: Node): Node | null =>
9692
}
9793

9894
const first = variants.get(0);
99-
const moneyNode = isTruthy(first.path(['onSale']))
100-
? first.path(['salePriceMoney'])
101-
: first.path(['priceMoney']);
95+
const moneyNode = isTruthy(first.path(['onSale'])) ? first.path(['salePriceMoney']) : first.path(['priceMoney']);
10296

10397
let pricingOptions = first.path(['pricingOptions']);
10498
let price = getAmountFromMoneyNode(moneyNode);

src/plugins/util.string.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { replaceMappedChars } from '../util';
22

3+
/**
4+
* Capitalize first letter of a string and lowercase the rest.
5+
*/
6+
export const capitalizeFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
7+
38
/**
49
* Strip text between '<' and '>' from string.
510
*/

0 commit comments

Comments
 (0)