Skip to content

Commit ca95cde

Browse files
authored
Merge pull request #38 from winglian/feature/lbf-to-newton
#29 convert pound-force/lbf to newtons
2 parents 55fb171 + 37dea9c commit ca95cde

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/conversion_helper.js

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const metricDistanceUnits = [/km/, /light-?years?/,
7777
/(?:milli|centi|deca|kilo)?met(?:re|er)s?/];
7878
const metricWeightUnits = [/kgs?/, /grams?/, /kilograms?/];
7979
const metricVolumeUnits = [/(?:milli|centi|deca|kilo)?lit(?:er|re)s?/, /(?:deca|kilo)?m(?:eters?)?(?:\^3| cubed?)/];
80+
const metricForceUnits = [/newtons?/, /dynes?/];
8081

8182
const ukSubreddits = ["britain", "british", "england", "english", "scotland", "scottish", "wales", "welsh", "ireland", "irish", "london", "uk"];
8283

@@ -264,6 +265,14 @@ const unitLookupList = [
264265
"conversionFunction" : (i) => distanceMap(i * 201.168),
265266
"ignoredUnits" : metricDistanceUnits
266267
},
268+
{
269+
"imperialUnits" : [/pounds?[ -]?(?:force)/, /lbf/, /lbs?[ -]?(?:force)/],
270+
"standardInputUnit" : " lbf",
271+
"isInvalidInput" : isZeroOrNegative,
272+
"isWeaklyInvalidInput" : isHyperbole,
273+
"conversionFunction" : (i) => createMap(i * 4.44822, " N"),
274+
"ignoredUnits" : metricForceUnits
275+
},
267276
{
268277
"imperialUnits" : "lbs?",
269278
"weakImperialUnits" : [/pounds?/],

test/converter-test.js

+31
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,37 @@ describe('Converter', () => {
346346
})
347347
})
348348

349+
context('lbf', () => {
350+
it('should convert', () => {
351+
testConvert(
352+
[
353+
"1 lbf",
354+
"2 lbf",
355+
"0.1 pound-force",
356+
"0.2 pounds-force",
357+
"10 pound force",
358+
"20 pounds force",
359+
"3 lb force",
360+
"4 lbs force",
361+
"5 lb-force",
362+
"6 lbs-force"
363+
],
364+
{
365+
"1 lbf" : "4.4 N",
366+
"2 lbf" : "9 N",
367+
"0.1 lbf" : "0.4 N",
368+
"0.2 lbf" : "0.9 N",
369+
"10 lbf" : "44 N",
370+
"20 lbf" : "90 N",
371+
"3 lbf" : "13 N",
372+
"4 lbf" : "18 N",
373+
"5 lbf" : "22 N",
374+
"6 lbf" : "27 N"
375+
}
376+
);
377+
});
378+
});
379+
349380
context('supported special characters', () => {
350381
it('should convert when starting with special characters', () => {
351382
testConvert(

0 commit comments

Comments
 (0)