Skip to content

Commit 0379a45

Browse files
committed
Remove string dependency.
1 parent 43adabe commit 0379a45

File tree

6 files changed

+5
-33
lines changed

6 files changed

+5
-33
lines changed

lib/handlers/get.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const fs = require('fs')
44
const glob = require('glob')
55
const _path = require('path')
66
const $rdf = require('rdflib')
7-
const S = require('string')
87
const Negotiator = require('negotiator')
98
const url = require('url')
109
const mime = require('mime-types')
@@ -160,14 +159,14 @@ function globHandler (req, res, next) {
160159

161160
debugGlob('found matches ' + matches)
162161
Promise.all(matches.map(match => new Promise((resolve, reject) => {
163-
const baseUri = utils.filenameToBaseUri(match, reqOrigin, root)
162+
const baseUri = reqOrigin + '/' + match.substr(root.length)
164163
fs.readFile(match, {encoding: 'utf8'}, function (err, fileData) {
165164
if (err) {
166165
debugGlob('error ' + err)
167166
return resolve()
168167
}
169168
aclAllow(match, req, res, function (allowed) {
170-
if (!S(match).endsWith('.ttl') || !allowed) {
169+
if (!match.endsWith('.ttl') || !allowed) {
171170
return resolve()
172171
}
173172
try {

lib/header.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports.addPermissions = addPermissions
66

77
const li = require('li')
88
const path = require('path')
9-
const S = require('string')
109
const metadata = require('./metadata.js')
1110
const debug = require('./debug.js')
1211
const utils = require('./utils.js')
@@ -54,7 +53,7 @@ function linksHandler (req, res, next) {
5453
return next(error(404, 'Trying to access metadata file as regular file'))
5554
}
5655
let fileMetadata = new metadata.Metadata()
57-
if (S(filename).endsWith('/')) {
56+
if (filename.endsWith('/')) {
5857
fileMetadata.isContainer = true
5958
fileMetadata.isBasicContainer = true
6059
} else {

lib/ldp-container.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const debug = require('./debug')
99
const error = require('./http-error')
1010
const fs = require('fs')
1111
const ns = require('solid-namespace')($rdf)
12-
const S = require('string')
1312
const mime = require('mime-types')
1413
const path = require('path')
1514

@@ -33,7 +32,7 @@ function addContainerStats (ldp, reqUri, filename, resourceGraph, next) {
3332

3433
function addFile (ldp, resourceGraph, containerUri, reqUri, uri, container, file, callback) {
3534
// Skip .meta and .acl
36-
if (S(file).endsWith(ldp.suffixMeta) || S(file).endsWith(ldp.suffixAcl)) {
35+
if (file.endsWith(ldp.suffixMeta) || file.endsWith(ldp.suffixAcl)) {
3736
return callback(null)
3837
}
3938

lib/utils.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
module.exports.uriToFilename = uriToFilename
22
module.exports.uriToRelativeFilename = uriToRelativeFilename
3-
module.exports.filenameToBaseUri = filenameToBaseUri
43
module.exports.getBaseUri = getBaseUri
54
module.exports.pathBasename = pathBasename
65
module.exports.getFullUri = getFullUri
76
module.exports.hasSuffix = hasSuffix
8-
module.exports.getResourceLink = getResourceLink
97
module.exports.parse = parse
108
module.exports.serialize = serialize
119
module.exports.translate = translate
@@ -17,7 +15,6 @@ module.exports.fullUrlForReq = fullUrlForReq
1715

1816
const fs = require('fs')
1917
const path = require('path')
20-
const S = require('string')
2118
const $rdf = require('rdflib')
2219
const from = require('from2')
2320
const url = require('url')
@@ -81,7 +78,7 @@ function uriToFilename (uri, base) {
8178
if (fileStats.isDirectory() && !filename.endsWith('/')) {
8279
filename += '/'
8380
} else if (fileStats.isFile() && filename.endsWith('/')) {
84-
filename = S(filename).chompRight('/').s
81+
filename = filename.substr(0, filename.length - 1)
8582
}
8683
} catch (err) {}
8784
return filename
@@ -93,11 +90,6 @@ function uriToRelativeFilename (uri, base) {
9390
return relative
9491
}
9592

96-
function filenameToBaseUri (filename, uri, base) {
97-
const uriPath = S(filename).strip(base).toString()
98-
return uri + '/' + uriPath
99-
}
100-
10193
function getBaseUri (req) {
10294
// Obtain the protocol from the configured server URI
10395
// (in case the server is running behind a reverse proxy)
@@ -145,17 +137,6 @@ function hasSuffix (path, suffixes) {
145137
return false
146138
}
147139

148-
function getResourceLink (filename, uri, base, suffix, otherSuffix) {
149-
const link = filenameToBaseUri(filename, uri, base)
150-
if (link.endsWith(suffix)) {
151-
return link
152-
} else if (link.endsWith(otherSuffix)) {
153-
return S(link).chompRight(otherSuffix).s + suffix
154-
} else {
155-
return link + suffix
156-
}
157-
}
158-
159140
function parse (data, baseUri, contentType, callback) {
160141
const graph = $rdf.graph()
161142
try {

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"solid-namespace": "^0.1.0",
7272
"solid-permissions": "^0.5.2",
7373
"solid-ws": "^0.2.3",
74-
"string": "^3.3.0",
7574
"ulid": "^0.1.0",
7675
"uuid": "^3.0.0",
7776
"valid-url": "^1.0.9",

0 commit comments

Comments
 (0)