@tabcat/orbit-db-fsstore
Advanced tools
Comparing version 3.1.4 to 3.1.5
{ | ||
"name": "@tabcat/orbit-db-fsstore", | ||
"version": "3.1.4", | ||
"version": "3.1.5", | ||
"description": "a custom orbit-db store representing a file system", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -14,2 +14,4 @@ [![npm (scoped)](https://img.shields.io/npm/v/@tabcat/orbit-db-fsstore)](https://www.npmjs.com/package/@tabcat/orbit-db-fsstore) | ||
##### Credit [File system on CRDT; Mehdi Ahmed-Nacer, Stéphane Martin, Pascal Urso](https://arxiv.org/pdf/1207.5990.pdf) for filesystem datatype and operation structure | ||
## FSStore Instance Methods API | ||
@@ -16,0 +18,0 @@ *check out [./test](./test) for more info* |
@@ -39,7 +39,10 @@ | ||
const pathPattern = /^(?:\/[^/]+)+$/ | ||
const pathValid = (path) => typeof path === 'string' && pathPattern.test(path) | ||
const namePattern = /^[^/]+$/ | ||
const nameValid = (name) => typeof name === 'string' && namePattern.test(name) | ||
const namePatternInfo = `match any string that does not contain '/'; regx: ${namePattern}` | ||
const pathPattern = /^(?:\/[^/]+)+$/ | ||
const pathValid = (path) => typeof path === 'string' && pathPattern.test(path) | ||
const pathPatternInfo = `match any string that is made of '/' + <name>; regx: ${pathPattern}` | ||
function joinPath (path, name) { | ||
@@ -53,5 +56,10 @@ if (!pathValid(path)) throw errors.pathValidNo(path) | ||
if (!pathValid(path)) throw errors.pathValidNo(path) | ||
return path.split('/')[path.split('/').length - 1] | ||
return path.slice(path.lastIndexOf('/') + 1) | ||
} | ||
function baseName (path) { | ||
if (!pathValid(path)) throw errors.pathValidNo(path) | ||
return path.slice(0, Math.max(path.lastIndexOf('/'), 0)) | ||
} | ||
const isOver = (p1, p2) => `${p1}/` === p2.slice(0, p1.length + 1) | ||
@@ -188,4 +196,4 @@ const isOneHigher = (p1, p2) => p1.split('/').length + 1 === p2.split('/').length | ||
const errors = { | ||
pathValidNo: (path) => new Error(`path ${path} is not valid`), | ||
nameValidNo: (name) => new Error(`name ${name} is not valid`), | ||
pathValidNo: (path) => new Error(`path ${path} is not valid, ${pathPatternInfo}`), | ||
nameValidNo: (name) => new Error(`name ${name} is not valid, ${namePatternInfo}`), | ||
pathExistNo: (path) => new Error(`path '${path}' does not exist`), | ||
@@ -227,3 +235,4 @@ pathExistYes: (path) => new Error(`path '${path}' already exists`), | ||
joinPath, | ||
pathName | ||
pathName, | ||
baseName | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18680
400
110