Skip to content

Commit 1d7417d

Browse files
authored
Remove dependency on common-sequence
There is little need to use common-sequence as a dependency since the implementation is very small. With iteration over for loops the implementation is even smaller. This change adds a `commonSequence` function that does the same thing the dependency did and removes the need to bring in even more 3rd party code into this repo.
1 parent 772a73b commit 1d7417d

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

helpers/helpers.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const ddata = require('./ddata')
22
const arrayify = require('array-back')
33
const handlebars = require('handlebars')
44
const util = require('util')
5-
const commonSequence = require('common-sequence')
65

76
/**
87
A library of helpers used exclusively by dmd.. dmd also registers helpers from ddata.
@@ -168,6 +167,15 @@ function _groupChildren (groupByFields, options) {
168167
return _groupBy(children, groupByFields)
169168
}
170169

170+
function *commonSequence(a, b) {
171+
const bSet = b.values()
172+
for (const aValue of a) {
173+
const { done, value: bValue } = bSet.next()
174+
if (done || aValue !== bValue) break
175+
yield aValue
176+
}
177+
}
178+
171179
/**
172180
takes the children of this, groups them, inserts group headings..
173181
*/
@@ -192,7 +200,7 @@ function _groupBy (identifiers, groupByFields) {
192200
let level = 0
193201
identifiers.forEach(function (identifier, index) {
194202
if (!deepEqual(identifier._group, prevGroup)) {
195-
const common = commonSequence(identifier._group, prevGroup)
203+
const common = Array.from(commonSequence(identifier._group, prevGroup))
196204
level = common.length
197205
identifier._group.forEach(function (group, i) {
198206
if (group !== common[i] && group !== null) {

0 commit comments

Comments
 (0)