Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string instead of String #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/manager/v2/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ export class Path

constructor(path : Path | string[] | string)
{
if(path.constructor === String)
if(typeof path === "string")
{
let sPath = path as string;
let sPath = path;
let doubleIndex : number;
while((doubleIndex = sPath.indexOf('//')) !== -1)
sPath = sPath.substr(0, doubleIndex) + sPath.substr(doubleIndex + 1);
sPath = sPath.slice(0, doubleIndex) + sPath.slice(doubleIndex + 1);
this.paths = sPath.replace(/(^\/|\/$)/g, '').split('/');
}
else if(path.constructor === Path)
this.paths = (path as Path).paths.filter((x) => true); // clone
else if(Array.isArray(path))
this.paths = path;
else
this.paths = path as string[];
this.paths = path.paths.slice(0); // clone

this.paths = this.paths.filter((p) => p.length > 0);
}
Expand Down
14 changes: 7 additions & 7 deletions src/manager/v2/fileSystem/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ export abstract class FileSystem implements ISerializableFileSystem
if(obj && obj.constructor === Function)
callbackFinal = obj as Return2Callback<Writable, boolean>;

const mode = _mode && _mode.constructor === String ? _mode as OpenWriteStreamMode : 'mustExist';
const mode: OpenWriteStreamMode = _mode && typeof _mode === "string" ? _mode : 'mustExist';
const path = new Path(_path);
let created = false;

Expand Down Expand Up @@ -1677,7 +1677,7 @@ export abstract class FileSystem implements ISerializableFileSystem
if(paths.length === 0)
return callback(null, base);

if(paths[0].constructor === String)
if(typeof paths[0] === "string")
base = base.concat((paths as string[]).map((s) => pPath.getChildPath(s)));
else
base = base.concat(paths as Path[]);
Expand Down Expand Up @@ -2005,9 +2005,9 @@ export abstract class FileSystem implements ISerializableFileSystem
{
this.create(ctx, rootPath, tree as ResourceType, callback);
}
else if(tree.constructor === String || tree.constructor === Buffer)
else if(typeof tree === "string" || tree.constructor === Buffer)
{
const data : String | Buffer = tree as any;
const data : string | Buffer = tree as any;
this.openWriteStream(ctx, rootPath, 'mustCreate', true, data.length, (e, w, created) => {
if(e)
return callback(e);
Expand All @@ -2027,7 +2027,7 @@ export abstract class FileSystem implements ISerializableFileSystem
.each(Object.keys(tree), (name, cb) => {
const value = tree[name];
const childPath = rootPath.getChildPath(name);
if(value.constructor === ResourceType || value.constructor === String || value.constructor === Buffer)
if(value.constructor === ResourceType || typeof value === "string" || value.constructor === Buffer)
{
this.addSubTree(ctx, childPath, value, cb)
}
Expand Down Expand Up @@ -2286,8 +2286,8 @@ export abstract class FileSystem implements ISerializableFileSystem
checkPrivilege(ctx : RequestContext, path : Path | string, privileges : string | string[], callback : ReturnCallback<boolean>)
checkPrivilege(ctx : RequestContext, path : Path | string, privileges : string | string[] | BasicPrivilege | BasicPrivilege[], callback : ReturnCallback<boolean>)
{
if(privileges.constructor === String)
privileges = [ privileges as string ];
if(typeof privileges === "string")
privileges = [ privileges ];

this.getFullPath(ctx, path, (e, fullPath) => {
this.privilegeManager(ctx, path, (e, privilegeManager) => {
Expand Down
4 changes: 2 additions & 2 deletions src/manager/v2/fileSystem/StorageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export class PerUserStorageManager implements IStorageManager
{
if(!value)
return 0;
if(value.constructor === String)
return (value as String).length;
if(typeof value === "string")
return value.length;
if(Array.isArray(value))
return (value as XMLElement[]).map((el) => this.evalPropValue(el)).reduce((p, n) => p + n, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/resource/v2/lock/Lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Lock
this.owner = owner;
this.depth = depth === undefined || depth === null ? -1 : depth;
this.uuid = Lock.generateUUID(this.expirationDate);
this.userUid = user ? user.constructor === String ? user as string : (user as IUser).uid : null;
this.userUid = user ? typeof user === "string" ? user : user.uid : null;
}

isSame(lock : Lock) : boolean
Expand Down
2 changes: 1 addition & 1 deletion src/server/v2/commands/Propfind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default class implements HTTPMethod

function displayValue(values : string[] | string, fn : () => void)
{
if(values.constructor === String ? tags[values as string].value : (values as string[]).some((n) => tags[n].value))
if(typeof values === "string" ? tags[values].value : values.some((n) => tags[n].value))
{
++nb;
process.nextTick(fn);
Expand Down
4 changes: 2 additions & 2 deletions src/server/v2/webDAVServer/StartStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export function executeRequest(req : http.IncomingMessage, res : http.ServerResp
const data = Buffer.alloc(base.headers.contentLength);
let index = 0;
req.on('data', (chunk) => {
if(chunk.constructor === String)
chunk = Buffer.from(chunk as string);
if(typeof chunk === "string")
chunk = Buffer.from(chunk);

for(let i = 0; i < chunk.length && index < data.length; ++i, ++index)
data[index] = (chunk as Buffer)[i];
Expand Down
6 changes: 3 additions & 3 deletions src/server/v2/webDAVServer/WebDAVServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ export class WebDAVServer
removeFileSystemSync(fs_path : Path | string | FileSystem, checkByReference : boolean = true) : number
{
let nb = 0;
if(fs_path.constructor === Path || fs_path.constructor === String)
if(fs_path.constructor === Path || typeof fs_path === "string")
{
const path = new Path(fs_path as (Path | string)).toString();
const path = new Path(fs_path).toString();
if(this.fileSystems[path] !== undefined)
{
delete this.fileSystems[path];
Expand Down Expand Up @@ -725,7 +725,7 @@ export class WebDAVServer
if(!this.events[event])
return;

this.events[event].forEach((l) => process.nextTick(() => l(ctx, fs, path.constructor === String ? new Path(path as string) : path as Path, data)));
this.events[event].forEach((l) => process.nextTick(() => l(ctx, fs, typeof path === "string" ? new Path(path) : path, data)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/user/v2/privilege/PrivilegeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class PrivilegeManager
if(resource.context.overridePrivileges || user && user.isAdministrator)
return callback(null, true);

if(_privilege.constructor !== String)
if(typeof _privilege !== "string")
{
new Workflow()
.each(_privilege as string[], (privilege, cb) => this.can(_fullPath, resource, privilege, cb))
Expand Down
2 changes: 1 addition & 1 deletion test/v2/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module.exports = (callback, options) => {

if(name !== undefined)
{
if(name.constructor === String)
if(typeof name === "string")
{
info.name = name;
info.startServer(undefined, autoStart);
Expand Down