import * as changeCase from 'change-case'
import pluralize from 'pluralize'

export default {
	...changeCase,
	pluralize,
	resourceize: function(string) {
		return pluralize(changeCase.camel(string))
	}
}

Object.map = function(source, func) {
	return Object.keys(source).map(key => {
		let value = source[key]
		return func(key, value)
	})
}

Object.get = function(source, keypath) {
	const keys = keypath.split('.')
	let key
	while (key = keys.shift()) {
		source = source[key]
		if (typeof source === 'undefined')
			return source
	}
	return source
}

Object.without = function(source, ...keys) {
	let copy = Object.assign({}, source)
	let i = keys.length
	while (i--) {
		let key = keys[i]
		copy[key] = undefined
		delete copy[key]
	}

	return copy
}

// eslint-disable-next-line
Promise.prototype.log = function() {
	return this.then(function(data) {
		console.log(data)
		return data
	})
}

import * as changeCase from 'change-case'
import pluralize from 'pluralize'

export default {
	...changeCase,
	pluralize,
	resourceize: function(string) {
		return pluralize(changeCase.camel(string))
	}
}

Object.map = function(source, func) {
	return Object.keys(source).map(key => {
		let value = source[key]
		return func(key, value)
	})
}

Object.get = function(source, keypath) {
	const keys = keypath.split('.')
	while (keys[1]) {
		let key = keys.shift()
		source = source[key]
		if (typeof source === 'undefined')
			return source
	}
	return source
}

Object.without = function(source, ...keys) {
	let copy = Object.assign({}, source)
	let i = keys.length
	while (i--) {
		let key = keys[i]
		copy[key] = undefined
		delete copy[key]
	}

	return copy
}

// eslint-disable-next-line
Promise.prototype.log = function() {
	return this.then(function(data) {
		console.log(data)
		return data
	})
}

Fix lint errors in Object.get
Fix lint errors in Object.get
