Skip to content

Commit 46b629b

Browse files
authored
Merge pull request #12160 from hasezoey/changeSplitToEach
style(buffer): change ".split" to "utils.each" for defining methods
2 parents 7dfe820 + 769aa21 commit 46b629b

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/types/buffer.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,26 @@ MongooseBuffer.mixin = {
142142
* Compile other Buffer methods marking this buffer as modified.
143143
*/
144144

145-
(
146-
// node < 0.5
147-
('writeUInt8 writeUInt16 writeUInt32 writeInt8 writeInt16 writeInt32 ' +
148-
'writeFloat writeDouble fill ' +
149-
'utf8Write binaryWrite asciiWrite set ' +
150-
151-
// node >= 0.5
152-
'writeUInt16LE writeUInt16BE writeUInt32LE writeUInt32BE ' +
153-
'writeInt16LE writeInt16BE writeInt32LE writeInt32BE ' + 'writeFloatLE writeFloatBE writeDoubleLE writeDoubleBE')
154-
).split(' ').forEach(function(method) {
155-
if (!Buffer.prototype[method]) {
156-
return;
157-
}
158-
MongooseBuffer.mixin[method] = function() {
159-
const ret = Buffer.prototype[method].apply(this, arguments);
160-
this._markModified();
161-
return ret;
162-
};
163-
});
145+
utils.each(
146+
[
147+
// node < 0.5
148+
'writeUInt8', 'writeUInt16', 'writeUInt32', 'writeInt8', 'writeInt16', 'writeInt32',
149+
'writeFloat', 'writeDouble', 'fill',
150+
'utf8Write', 'binaryWrite', 'asciiWrite', 'set',
151+
152+
// node >= 0.5
153+
'writeUInt16LE', 'writeUInt16BE', 'writeUInt32LE', 'writeUInt32BE',
154+
'writeInt16LE', 'writeInt16BE', 'writeInt32LE', 'writeInt32BE', 'writeFloatLE', 'writeFloatBE', 'writeDoubleLE', 'writeDoubleBE']
155+
, function(method) {
156+
if (!Buffer.prototype[method]) {
157+
return;
158+
}
159+
MongooseBuffer.mixin[method] = function() {
160+
const ret = Buffer.prototype[method].apply(this, arguments);
161+
this._markModified();
162+
return ret;
163+
};
164+
});
164165

165166
/**
166167
* Converts this buffer to its Binary type representation.

0 commit comments

Comments
 (0)