UNPKG

ctrip-apollo-ex

Version:

The most delightful and handy Node.js client for ctrip apollo configuration service

40 lines (32 loc) 767 B
const {isString} = require('core-util-is') const {error} = require('./error') const createKey = (...args) => Buffer.from(args.join('|')).toString('base64') class Base { constructor (options, Child, key, errorCode) { this._options = options this._Child = Child this._children = Object.create(null) this._errorCode = errorCode this._key = key } _child (name, ...args) { if (!isString(name)) { throw error(this._errorCode, name) } if (name in this._children) { return this._children[name] } return this._children[name] = this._create(name, ...args) } _create (name) { return new this._Child({ ...this._options, [this._key]: name }) } } module.exports = { createKey, Base }