Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit 0aeb0f6

Browse files
hugomrdiasachingbrain
authored andcommitted
fix: remove leftpad (#28)
left-pad is deprecated in favor of String.prototype.padStart()
1 parent f25e5ca commit 0aeb0f6

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"hamt-sharding": "~0.0.2",
6363
"ipfs-unixfs": "~0.1.16",
6464
"ipld-dag-pb": "~0.17.2",
65-
"left-pad": "^1.3.0",
6665
"multicodec": "~0.5.1",
6766
"multihashing-async": "~0.7.0",
6867
"superstruct": "~0.6.1"

src/dir-sharded.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const leftPad = require('left-pad')
43
const {
54
DAGLink,
65
DAGNode
@@ -95,7 +94,7 @@ async function * flush (path, bucket, ipld, options) {
9594
continue
9695
}
9796

98-
const labelPrefix = leftPad(i.toString(16).toUpperCase(), 2, '0')
97+
const labelPrefix = i.toString(16).toUpperCase().padStart(2, '0')
9998

10099
if (Bucket.isBucket(child)) {
101100
let shard

test/builder-dir-sharding.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ chai.use(require('dirty-chai'))
99
const expect = chai.expect
1010
const IPLD = require('ipld')
1111
const inMemory = require('ipld-in-memory')
12-
const leftPad = require('left-pad')
1312
const all = require('async-iterator-all')
1413
const last = require('async-iterator-last')
1514

@@ -133,7 +132,7 @@ describe('builder: directory sharding', () => {
133132
[Symbol.asyncIterator]: async function * () {
134133
for (let i = 0; i < maxDirs; i++) {
135134
yield {
136-
path: 'big/' + leftPad(i.toString(), 4, '0'),
135+
path: 'big/' + i.toString().padStart(4, '0'),
137136
content: Buffer.from(i.toString())
138137
}
139138
}
@@ -152,7 +151,7 @@ describe('builder: directory sharding', () => {
152151
[Symbol.asyncIterator]: async function * () {
153152
for (let i = 0; i < maxDirs; i++) {
154153
yield {
155-
path: 'big/' + leftPad(i.toString(), 4, '0'),
154+
path: 'big/' + i.toString().padStart(4, '0'),
156155
content: Buffer.from(i.toString())
157156
}
158157
}
@@ -196,7 +195,7 @@ describe('builder: directory sharding', () => {
196195
}
197196

198197
yield {
199-
path: dir.concat(leftPad(i.toString(), 4, '0')).join('/'),
198+
path: dir.concat(i.toString().padStart(4, '0')).join('/'),
200199
content: Buffer.from(i.toString())
201200
}
202201

@@ -267,7 +266,7 @@ describe('builder: directory sharding', () => {
267266
const pathElements = path.split('/')
268267
expect(pathElements.length).to.equal(depth + 1)
269268
const lastElement = pathElements[pathElements.length - 1]
270-
expect(lastElement).to.equal(leftPad(index.toString(), 4, '0'))
269+
expect(lastElement).to.equal(index.toString().padStart(4, '0'))
271270
expect(entries[path].content).to.equal(index.toString())
272271
}
273272
index++

0 commit comments

Comments
 (0)