Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit f9b0652

Browse files
EstebanMarinKent C. Dodds
authored andcommitted
feat(dec2hex): add dec2hex function (#202) (#202)
@kentcdodds The function and test were stright forward, however, I am gettting a strange error, confirmed by `eslint`: `[eslint] dec2hex not found in '../src'` So when I run the test, it fails because it is not finding the module. I tried adding another `.js` module, and odd enough I was getting the same issue. I also tried default import like `import dec2hex from '../src'` but then I get `[eslint] No default export found in module.` which makes sense if the module is not found I ran `npm run lint` did not get any linting errors, and after ran a `npm build` too, but I was not able to solve it. Can you please provide a guide so I can make the test run and be able to make the PR Many thanks!!!!
1 parent d39b0aa commit f9b0652

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/dec2hex.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default dec2hex
2+
3+
/**
4+
* Original source: https://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript
5+
* This method will return the Hex equivalent or any num
6+
* However the native function can only handle Number.MAX_SAFE_INTEGER => 9007199254740991
7+
* @param {Number} num - the array to calculate average
8+
* @return {String} - String with Hex value
9+
*/
10+
11+
function dec2hex(num) {
12+
const hextString = num.toString(16)
13+
return hextString
14+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import multiply from './multiply'
3030
import square from './square'
3131
import cube from './cube'
3232
import sum from './sum'
33+
import dec2hex from './dec2hex'
3334
import dec2bin from './dec2bin'
3435
import searchAndReplace from './search-and-replace'
3536
import sqrt from './sqrt'
@@ -150,4 +151,5 @@ export {
150151
curry,
151152
textJustification,
152153
removeProperty,
154+
dec2hex,
153155
}

test/dec2hex.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from 'ava'
2+
import {dec2hex} from '../src'
3+
4+
test('Simple Conversion', t => {
5+
const number = 60
6+
const expected = '3c'
7+
const actual = dec2hex(number)
8+
t.deepEqual(actual, expected)
9+
})

0 commit comments

Comments
 (0)