Skip to content

Commit

Permalink
fixed camelCase/camel_case property conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
xpl committed Jan 21, 2018
1 parent 9dc05cf commit 931922a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ module.exports = class Exchange {

this.arrayConcat = (a, b) => a.concat (b)

const names = Object.getOwnPropertyNames (this).concat (
Object.getOwnPropertyNames (this.constructor.prototype))

for (const k of names)
this[unCamelCase (k)] = this[k]
const unCamelCaseProperties = (obj = this) => {
if (obj !== null) {
for (const k of Object.getOwnPropertyNames (obj)) {
this[unCamelCase (k)] = this[k]
}
unCamelCaseProperties (Object.getPrototypeOf (obj))
}
}
unCamelCaseProperties ()

/* exchange's capabilities (overrideable) */

Expand Down
7 changes: 7 additions & 0 deletions js/test/test_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ describe ('ccxt base code', () => {

})

it ('camelCase/camel_case property conversion works #2', () => {

class Derived extends ccxt.Exchange {}
const derived = new Derived ()
assert (typeof derived.load_markets === 'function')
})

it ('legacy .hasSomething maps to has.something automatically', () => {

const exchange = new ccxt.Exchange ({
Expand Down

0 comments on commit 931922a

Please sign in to comment.