Skip to content

Commit 6bd2c5e

Browse files
committed
factor object-tools out of project
1 parent cca6f01 commit 6bd2c5e

4 files changed

Lines changed: 47 additions & 12 deletions

File tree

es5/transform.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var testValue = require('test-value');
55
var where = testValue.where;
66
var arrayify = require('array-back');
77
var extract = require('reduce-extract');
8+
var pick = require('lodash.pick');
9+
var omit = require('lodash.omit');
810

911
module.exports = transform;
1012

@@ -103,8 +105,33 @@ function createConstructor(class_) {
103105
}
104106

105107
var replacements = [];
106-
class_ = o.clone(class_);
107-
var constructor = o.extract(class_, ['description', 'params', 'examples', 'returns', 'exceptions']);
108+
class_ = Object.assign({}, class_);
109+
var constructorProperties = ['description', 'params', 'examples', 'returns', 'exceptions'];
110+
var constructor = pick(class_, constructorProperties);
111+
var _iteratorNormalCompletion = true;
112+
var _didIteratorError = false;
113+
var _iteratorError = undefined;
114+
115+
try {
116+
for (var _iterator = constructorProperties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
117+
var prop = _step.value;
118+
delete class_[prop];
119+
}
120+
} catch (err) {
121+
_didIteratorError = true;
122+
_iteratorError = err;
123+
} finally {
124+
try {
125+
if (!_iteratorNormalCompletion && _iterator.return) {
126+
_iterator.return();
127+
}
128+
} finally {
129+
if (_didIteratorError) {
130+
throw _iteratorError;
131+
}
132+
}
133+
}
134+
108135
if (class_.classdesc) {
109136
class_.description = class_.classdesc;
110137
delete class_.classdesc;
@@ -233,7 +260,7 @@ function cleanProperties(doclet) {
233260
}
234261

235262
function wantedProperties(input) {
236-
return o.without(input, ['comment', 'meta', 'undocumented', '___id', '___s']);
263+
return omit(input, ['comment', 'meta', 'undocumented', '___id', '___s']);
237264
}
238265

239266
function buildTodoList(doclet) {
@@ -324,7 +351,7 @@ function sortIdentifier(doclet) {
324351

325352
function update(array, query, newValues) {
326353
for (var i = 0; i < array.length; i++) {
327-
if (o.exists(array[i], query)) {
354+
if (testValue(array[i], query)) {
328355
var values = typeof newValues === 'function' ? newValues(array[i]) : newValues;
329356
for (var prop in values) {
330357
if (values[prop] !== undefined) array[i][prop] = values[prop];

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ if (!detect.newArrayFeatures()) {
44
require('core-js/es6/array')
55
}
66

7+
if (!Object.assign) {
8+
require('core-js/es6/object')
9+
}
10+
711
if (detect.all('class', 'arrowFunction', 'let', 'const')) {
812
module.exports = require('./lib/jsdoc-parse')
913
} else {
10-
require('core-js/es6/object')
1114
module.exports = require('./es5/jsdoc-parse')
1215
}

lib/transform.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const testValue = require('test-value')
44
const where = testValue.where
55
const arrayify = require('array-back')
66
const extract = require('reduce-extract')
7+
const pick = require('lodash.pick')
8+
const omit = require('lodash.omit')
79

810
/**
911
* @module transform
@@ -122,9 +124,11 @@ function createConstructor (class_) {
122124
throw new Error('should only pass a class to createConstructor')
123125
}
124126

125-
var replacements = []
126-
class_ = o.clone(class_)
127-
var constructor = o.extract(class_, [ 'description', 'params', 'examples', 'returns', 'exceptions' ])
127+
const replacements = []
128+
class_ = Object.assign({}, class_)
129+
const constructorProperties = [ 'description', 'params', 'examples', 'returns', 'exceptions' ]
130+
const constructor = pick(class_, constructorProperties)
131+
for (const prop of constructorProperties) delete class_[prop]
128132
if (class_.classdesc) {
129133
class_.description = class_.classdesc
130134
delete class_.classdesc
@@ -257,7 +261,7 @@ function cleanProperties (doclet) {
257261
}
258262

259263
function wantedProperties (input) {
260-
return o.without(input, [ 'comment', 'meta', 'undocumented', '___id', '___s' ])
264+
return omit(input, [ 'comment', 'meta', 'undocumented', '___id', '___s' ])
261265
}
262266

263267
function buildTodoList (doclet) {
@@ -355,7 +359,7 @@ function sortIdentifier (doclet) {
355359

356360
function update (array, query, newValues) {
357361
for (var i = 0; i < array.length; i++) {
358-
if (o.exists(array[i], query)) {
362+
if (testValue(array[i], query)) {
359363
var values = typeof newValues === 'function' ? newValues(array[i]) : newValues
360364
for (var prop in values) {
361365
if (values[prop] !== undefined) array[i][prop] = values[prop]

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
"array-back": "^1.0.3",
2626
"core-js": "^2.4.1",
2727
"feature-detect-es6": "^1.3.1",
28-
"object-tools": "^2.0.6",
28+
"lodash.omit": "^4.4.0",
29+
"lodash.pick": "^4.3.0",
2930
"reduce-extract": "^1.0.0",
3031
"test-value": "^2.0.0"
3132
},
3233
"devDependencies": {
3334
"babel-preset-es2015": "^6.9.0",
34-
"tape": "^4.6"
35+
"tape": "^4.6.0"
3536
},
3637
"standard": {
3738
"ignore": [

0 commit comments

Comments
 (0)