UNPKG

react-native-cloud-store

Version:
41 lines (38 loc) 1.24 kB
export class PathUtils { static subPath(from, to) { from = suffixIf(prefixIf(from, "/"), "/"); to = suffixIf(prefixIf(to, "/"), "/"); if (!to.startsWith(from)) { throw new Error(`${from} not a sub path to ${to}`); } return prefixIf(rmSuffixIf(to.slice(from.length), "/"), '/'); } static join() { for (var _len = arguments.length, segments = new Array(_len), _key = 0; _key < _len; _key++) { segments[_key] = arguments[_key]; } return segments.reduce((acc, cur) => { return acc + rmSuffixIf(prefixIf(cur, "/"), "/"); }, ""); } // change ".xx.icloud" to "xx" static iCloudRemoveDotExt(path) { return path.replace(/(.*?)(\.(.*?)\.icloud)$/, "$1$3"); } static ext(path) { return path.split(".").pop(); } } function prefixIf(path, prefix) { return path.startsWith(prefix) ? path : prefix + path; } function suffixIf(path, suffix) { return path.endsWith(suffix) ? path : path + suffix; } // function rmPrefixIf(path: string, prefix: string) { // return path.startsWith(prefix) ? path.slice(prefix.length) : path; // } function rmSuffixIf(path, suffix) { return path.endsWith(suffix) ? path.slice(0, -suffix.length) : path; } //# sourceMappingURL=path.js.map