UNPKG

parse-js

Version:

Utility library for object structure conversion.

24 lines (17 loc) 534 B
'use strict'; var _get = require('lodash/get'); var _set = require('lodash/set'); function SelectTransformer(path) { if (!(this instanceof SelectTransformer)) { return this.transform(new SelectTransformer(path)); } this._path = path; } SelectTransformer.prototype.parse = function (source) { return _get(source, this._path); }; SelectTransformer.prototype.reverse = function (source) { if (typeof source === 'undefined') return source; return _set({}, this._path, source); }; module.exports = SelectTransformer;