Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add si prefixes #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions src/units/length.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import utils from '../utils.js'

const RATIO = 3.28084
const RATIO = {
metric: {
astronomical: 1.496e+11,
imperial: 3.28084
},
astronomical: {
metric: 1 / 1.496e+11,
imperial: 1 / 4.908e+11
},
imperial: {
astronomical: 4.908e+11,
metric: 1 / 3.28084
}
}

const FUNCTION = (val, origin, destination) => { return val * RATIO[origin][destination] }

const length = {
metric: {
baseUnit: 'm',
transform: (val) => { return val * RATIO },
transform: FUNCTION,
ym: {
name: {
singular: 'Yoctometre',
singular: 'Yeptometre',
plural: 'Yeptometres'
},
to_anchor: 1 / 1000000000000000000000000
Expand Down Expand Up @@ -156,7 +171,7 @@ const length = {
},
imperial: {
baseUnit: 'ft',
transform: (val) => { return val * 1 / RATIO },
transform: FUNCTION,
'in': {
name: {
singular: 'Inch',
Expand Down Expand Up @@ -206,6 +221,31 @@ const length = {
},
to_anchor: 6076.12
}
},
astronomical: {
baseUnit: 'au',
transform: FUNCTION,
au: {
name: {
singular: 'Astronomical unit',
plural: 'Astronomical units'
},
to_anchor: 1
},
ly: {
name: {
singular: 'Light-year',
plural: 'Light years'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dash missing

},
to_anchor: 63241.1
},
pc: {
name: {
singular: 'Parsec',
plural: 'Parsecs'
},
to_anchor: 206265
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Converter.prototype.to = function (to) {
}

if (this.origin.system !== this.destination.system) {
result = this.definitions[this.origin.system].transform(result)
result = this.definitions[this.origin.system].transform(result, this.origin.system, this.destination.system)
}

if (this.destination.unit.anchor_shift !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('Test the possibilities', () => {
})

test('m possibilities', () => {
const expected = ['ym', 'zm', 'am', 'fm', 'pm', 'nm', 'µm', 'mm', 'cm', 'dm', 'm', 'dam', 'hm', 'km', 'Mm', 'Gm', 'Tm', 'Pm', 'Em', 'Zm', 'Ym', 'in', 'yd', 'ft-us', 'ft', 'fathom', 'mi', 'nMi']
const expected = ['ym', 'zm', 'am', 'fm', 'pm', 'nm', 'µm', 'mm', 'cm', 'dm', 'm', 'dam', 'hm', 'km', 'Mm', 'Gm', 'Tm', 'Pm', 'Em', 'Zm', 'Ym', 'in', 'yd', 'ft-us', 'ft', 'fathom', 'mi', 'nMi', 'au', 'ly', 'pc']
expect(converter.length().from('m').possibilities()).toEqual(expected)
})

Expand All @@ -174,7 +174,7 @@ describe('Test the possibilities', () => {
})

test('length possibilities', () => {
const expected = ['ym', 'zm', 'am', 'fm', 'pm', 'nm', 'µm', 'mm', 'cm', 'dm', 'm', 'dam', 'hm', 'km', 'Mm', 'Gm', 'Tm', 'Pm', 'Em', 'Zm', 'Ym', 'in', 'yd', 'ft-us', 'ft', 'fathom', 'mi', 'nMi']
const expected = ['ym', 'zm', 'am', 'fm', 'pm', 'nm', 'µm', 'mm', 'cm', 'dm', 'm', 'dam', 'hm', 'km', 'Mm', 'Gm', 'Tm', 'Pm', 'Em', 'Zm', 'Ym', 'in', 'yd', 'ft-us', 'ft', 'fathom', 'mi', 'nMi', 'au', 'ly', 'pc']
expect(converter.length().possibilities()).toEqual(expected)
})

Expand Down