diff --git a/index.js b/index.js index 99798bb..11d43e1 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,6 @@ 'use strict'; +const optsSymbol = Symbol('option-chain-opts'); + module.exports = (options, fn, target) => { const chainables = options.chainableMethods || {}; const spread = options.spread; @@ -14,6 +16,13 @@ module.exports = (options, fn, target) => { } }); } + Object.defineProperty(target, optsSymbol, { + enumerable: true, + configurable: true, + get() { + return getter(); + } + }); } function wrap(createOpts, extensionOpts, ctx) { @@ -53,3 +62,5 @@ module.exports = (options, fn, target) => { return wrap(copyDefaults); }; + +module.exports.optsSymbol = optsSymbol; diff --git a/test.js b/test.js index 6fb706b..f968503 100644 --- a/test.js +++ b/test.js @@ -128,3 +128,15 @@ test('spread option spreads arguments', t => { t.deepEqual(def('a', 'b'), [{}, 'a', 'b']); t.deepEqual(def.foo('c', 'd'), [{foo: true}, 'c', 'd']); }); + +test('access opts with opts symbol', t => { + const def = fn({ + chainableMethods: { + foo: {foo: true} + } + }, () => { + + }); + + t.deepEqual(def.foo[fn.optsSymbol], {foo: true}); +});