Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@furystack/utils

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@furystack/utils - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

2

dist/index.d.ts
export * from './disposable';
export * from './deep-merge';
export * from './filter-async';
export * from './debounce';
export * from './observable-value';
export * from './retrier';
export * from './value-observer';

@@ -8,0 +6,0 @@ export * from './path-helper';

@@ -6,6 +6,4 @@ "use strict";

(0, tslib_1.__exportStar)(require("./deep-merge"), exports);
(0, tslib_1.__exportStar)(require("./filter-async"), exports);
(0, tslib_1.__exportStar)(require("./debounce"), exports);
(0, tslib_1.__exportStar)(require("./observable-value"), exports);
(0, tslib_1.__exportStar)(require("./retrier"), exports);
(0, tslib_1.__exportStar)(require("./value-observer"), exports);

@@ -12,0 +10,0 @@ (0, tslib_1.__exportStar)(require("./path-helper"), exports);

@@ -16,3 +16,3 @@ /**

* Splits a full path into path segments,
* e.g.: /Root/Example('Content1') will be ["Root", "Example", "('Content1')"]
* e.g.: /Root/Example/stuff
*

@@ -24,37 +24,2 @@ * @param path The path to be splitted

/**
* Checks if a specific segment is an Item segment or not (like "('Content1')"" or "(654)")
*
* @param segment The segment to be examined
* @returns a boolean value that indicates if the segment is an item segment
*/
static isItemSegment(segment: string): boolean;
/**
* Method that tells if a path is an item path or an item reference path (e.g. contains an Item segment).
*
* @param {string} path Path that you want to test.
* @returns {boolean} Returns if the given path is a path of a Content or not.
*/
static isItemPath(path: string): boolean;
/**
* Returns the full path for a content based on its Id or Path
*
* @param {string | number} idOrPath the Id Or Path of the content
* @returns A full Id or Path-based url of the content (e.g. *'/content(1)'* or *'/Root/Example/('Content')'*)
*/
static getContentUrl(idOrPath: string | number): string;
/**
* Method that gets the URL that refers to a single item in the Sense/Net Content Repository
*
* @param {string} path Path that you want to format.
* @returns {string} Path in entity format e.g. /workspaces('project') from /workspaces/project
*/
static getContentUrlByPath(path: string): string;
/**
* Method that gets the URL that refers to a single item in the Sense/Net Content Repository by its Id
*
* @param id {number} Id of the Content.
* @returns {string} e.g. /content(123)
*/
static getContentUrlbyId(id: number): string;
/**
* Method that allows to join paths without multiple or missing slashes

@@ -61,0 +26,0 @@ *

@@ -27,3 +27,3 @@ "use strict";

* Splits a full path into path segments,
* e.g.: /Root/Example('Content1') will be ["Root", "Example", "('Content1')"]
* e.g.: /Root/Example/stuff
*

@@ -34,76 +34,5 @@ * @param path The path to be splitted

static getSegments(path) {
return path
.split(/\/|[(][']|[(]/g)
.filter((segment) => segment && segment.length)
.map((segment) => {
if (segment.endsWith("')")) {
segment = `('${segment}`;
}
else if (segment.endsWith(')')) {
segment = `(${segment}`;
}
return segment;
});
return path.split('/').filter((segment) => segment && segment.length);
}
/**
* Checks if a specific segment is an Item segment or not (like "('Content1')"" or "(654)")
*
* @param segment The segment to be examined
* @returns a boolean value that indicates if the segment is an item segment
*/
static isItemSegment(segment) {
return RegExp(/^\('+[\s\S]+'\)$/).test(segment) || RegExp(/^\(+\d+\)$/).test(segment);
}
/**
* Method that tells if a path is an item path or an item reference path (e.g. contains an Item segment).
*
* @param {string} path Path that you want to test.
* @returns {boolean} Returns if the given path is a path of a Content or not.
*/
static isItemPath(path) {
const segments = this.getSegments(path);
const itemSegment = segments.find((s) => this.isItemSegment(s));
return itemSegment && itemSegment.length ? true : false;
}
/**
* Returns the full path for a content based on its Id or Path
*
* @param {string | number} idOrPath the Id Or Path of the content
* @returns A full Id or Path-based url of the content (e.g. *'/content(1)'* or *'/Root/Example/('Content')'*)
*/
static getContentUrl(idOrPath) {
const parsed = parseInt(idOrPath, 10);
if (isNaN(parsed)) {
return this.getContentUrlByPath(idOrPath.toString());
}
else {
return this.getContentUrlbyId(parsed);
}
}
/**
* Method that gets the URL that refers to a single item in the Sense/Net Content Repository
*
* @param {string} path Path that you want to format.
* @returns {string} Path in entity format e.g. /workspaces('project') from /workspaces/project
*/
static getContentUrlByPath(path) {
if (!path) {
throw Error('Path is empty');
}
const segments = this.getSegments(path);
if (!this.isItemPath(path)) {
segments[segments.length - 1] = `('${segments[segments.length - 1]}')`;
}
return segments.join('/');
}
/**
* Method that gets the URL that refers to a single item in the Sense/Net Content Repository by its Id
*
* @param id {number} Id of the Content.
* @returns {string} e.g. /content(123)
*/
static getContentUrlbyId(id) {
return `content(${id})`;
}
/**
* Method that allows to join paths without multiple or missing slashes

@@ -110,0 +39,0 @@ *

@@ -9,22 +9,2 @@ "use strict";

exports.pathHelperTests = describe('PathHelper', () => {
describe('#isItemSegment()', () => {
it('Should return true for item segments with string key "(\'Item1\')"', () => {
expect(path_helper_1.PathHelper.isItemSegment("('Item1')")).toBe(true);
});
it('Should return true for item segments with numeric key "(42)"', () => {
expect(path_helper_1.PathHelper.isItemSegment('(42)')).toBe(true);
});
it('Should return false for string keys w/o quotes', () => {
expect(path_helper_1.PathHelper.isItemSegment('(invalidValue)')).toBe(false);
});
it('Should return false for invalid string keys', () => {
expect(path_helper_1.PathHelper.isItemSegment('(123invalidValue)')).toBe(false);
});
it('Should return false for non-item segments', () => {
expect(path_helper_1.PathHelper.isItemSegment('Item1')).toBe(false);
});
it('Should return false for inconsistent quotation', () => {
expect(path_helper_1.PathHelper.isItemSegment("('123invalidValue)")).toBe(false);
});
});
describe('#trimSlashes()', () => {

@@ -44,59 +24,2 @@ it('should trim from the beginning of the segment', () => {

});
describe('#isItemPath()', () => {
it('should return true for item paths', () => {
const isAnItem = path_helper_1.PathHelper.isItemPath("/workspace('project')");
expect(isAnItem).toBe(true);
});
it('should return false for collection paths', () => {
const isNotAnItem = path_helper_1.PathHelper.isItemPath('/workspace/project');
expect(isNotAnItem).toBe(false);
});
it('should return true for reference paths', () => {
const isAnItem = path_helper_1.PathHelper.isItemPath("/workspace/('project')/CustomAction");
expect(isAnItem).toBe(true);
});
it('should return true for reference paths with ids', () => {
const isAnItem = path_helper_1.PathHelper.isItemPath('/workspaces/(22)/CustomAction');
expect(isAnItem).toBe(true);
});
});
describe('#getContentUrlbyId()', () => {
it('should return by path if the provided value is a path', () => {
const url = path_helper_1.PathHelper.getContentUrl('/workspace/project');
expect(url).toBe("workspace/('project')");
});
it('should return by id if the provided value is id', () => {
const contentUrl = path_helper_1.PathHelper.getContentUrl(1);
expect(contentUrl).toBe('content(1)');
});
});
describe('#getContentUrlbyId()', () => {
it('should create the path with the correct format', () => {
const contentUrl = path_helper_1.PathHelper.getContentUrlbyId(1);
expect(contentUrl).toBe('content(1)');
});
});
describe('#getContentUrlByPath()', () => {
it('should return a proper item path by the given path', () => {
const contentUrl = path_helper_1.PathHelper.getContentUrlByPath('/workspace/project');
expect(contentUrl).toBe("workspace/('project')");
});
it('should return the path itself if it is an item path already', () => {
const contentUrl = path_helper_1.PathHelper.getContentUrlByPath("/workspace('project')");
expect(contentUrl).toBe("workspace/('project')");
});
it('should return the path itself for reference paths', () => {
const contentUrl = path_helper_1.PathHelper.getContentUrlByPath("/workspace('project')/Owner");
expect(contentUrl).toBe("workspace/('project')/Owner");
});
it('should return an error message if the given argument is an empty string', () => {
expect(() => {
path_helper_1.PathHelper.getContentUrlByPath('');
}).toThrow();
});
it('should return a proper item path for Root only', () => {
const path = path_helper_1.PathHelper.getContentUrlByPath('/Root');
expect(path).toBe("('Root')");
});
});
describe('#joinPaths()', () => {

@@ -129,12 +52,9 @@ it('should join with slashes', () => {

it('Should split the path to segments', () => {
expect(path_helper_1.PathHelper.getSegments("Root/Example('Content1')")).toEqual(['Root', 'Example', "('Content1')"]);
expect(path_helper_1.PathHelper.getSegments("Root/Example/('Content1')")).toEqual(['Root', 'Example', "('Content1')"]);
});
});
describe('#getParentPath()', () => {
it('Should return the parent path in case of more than 1 segments', () => {
it('Should return the parent path', () => {
expect(path_helper_1.PathHelper.getParentPath('Root/Example/Content')).toBe('Root/Example');
});
it('Should return the parent path in case of more than 1 segments with item path', () => {
expect(path_helper_1.PathHelper.getParentPath("Root/Example('Content')")).toBe('Root/Example');
});
it('Should return the path in case of 1 segments', () => {

@@ -141,0 +61,0 @@ expect(path_helper_1.PathHelper.getParentPath('Root')).toBe('Root');

4

package.json
{
"name": "@furystack/utils",
"version": "2.0.2",
"version": "2.0.3",
"description": "General utilities",

@@ -39,3 +39,3 @@ "main": "dist/index.js",

},
"gitHead": "302c069cac7bc920a20649ee38e574b0e7adcb9e"
"gitHead": "dcee00dfb4035fe382ec726af4d614ef9d8a579f"
}
export * from './disposable'
export * from './deep-merge'
export * from './filter-async'
export * from './debounce'
export * from './observable-value'
export * from './retrier'
export * from './value-observer'

@@ -8,0 +6,0 @@ export * from './path-helper'

@@ -7,28 +7,2 @@ import { PathHelper } from './path-helper'

export const pathHelperTests = describe('PathHelper', () => {
describe('#isItemSegment()', () => {
it('Should return true for item segments with string key "(\'Item1\')"', () => {
expect(PathHelper.isItemSegment("('Item1')")).toBe(true)
})
it('Should return true for item segments with numeric key "(42)"', () => {
expect(PathHelper.isItemSegment('(42)')).toBe(true)
})
it('Should return false for string keys w/o quotes', () => {
expect(PathHelper.isItemSegment('(invalidValue)')).toBe(false)
})
it('Should return false for invalid string keys', () => {
expect(PathHelper.isItemSegment('(123invalidValue)')).toBe(false)
})
it('Should return false for non-item segments', () => {
expect(PathHelper.isItemSegment('Item1')).toBe(false)
})
it('Should return false for inconsistent quotation', () => {
expect(PathHelper.isItemSegment("('123invalidValue)")).toBe(false)
})
})
describe('#trimSlashes()', () => {

@@ -52,71 +26,2 @@ it('should trim from the beginning of the segment', () => {

describe('#isItemPath()', () => {
it('should return true for item paths', () => {
const isAnItem = PathHelper.isItemPath("/workspace('project')")
expect(isAnItem).toBe(true)
})
it('should return false for collection paths', () => {
const isNotAnItem = PathHelper.isItemPath('/workspace/project')
expect(isNotAnItem).toBe(false)
})
it('should return true for reference paths', () => {
const isAnItem = PathHelper.isItemPath("/workspace/('project')/CustomAction")
expect(isAnItem).toBe(true)
})
it('should return true for reference paths with ids', () => {
const isAnItem = PathHelper.isItemPath('/workspaces/(22)/CustomAction')
expect(isAnItem).toBe(true)
})
})
describe('#getContentUrlbyId()', () => {
it('should return by path if the provided value is a path', () => {
const url = PathHelper.getContentUrl('/workspace/project')
expect(url).toBe("workspace/('project')")
})
it('should return by id if the provided value is id', () => {
const contentUrl = PathHelper.getContentUrl(1)
expect(contentUrl).toBe('content(1)')
})
})
describe('#getContentUrlbyId()', () => {
it('should create the path with the correct format', () => {
const contentUrl = PathHelper.getContentUrlbyId(1)
expect(contentUrl).toBe('content(1)')
})
})
describe('#getContentUrlByPath()', () => {
it('should return a proper item path by the given path', () => {
const contentUrl = PathHelper.getContentUrlByPath('/workspace/project')
expect(contentUrl).toBe("workspace/('project')")
})
it('should return the path itself if it is an item path already', () => {
const contentUrl = PathHelper.getContentUrlByPath("/workspace('project')")
expect(contentUrl).toBe("workspace/('project')")
})
it('should return the path itself for reference paths', () => {
const contentUrl = PathHelper.getContentUrlByPath("/workspace('project')/Owner")
expect(contentUrl).toBe("workspace/('project')/Owner")
})
it('should return an error message if the given argument is an empty string', () => {
expect(() => {
PathHelper.getContentUrlByPath('')
}).toThrow()
})
it('should return a proper item path for Root only', () => {
const path = PathHelper.getContentUrlByPath('/Root')
expect(path).toBe("('Root')")
})
})
describe('#joinPaths()', () => {

@@ -155,3 +60,3 @@ it('should join with slashes', () => {

it('Should split the path to segments', () => {
expect(PathHelper.getSegments("Root/Example('Content1')")).toEqual(['Root', 'Example', "('Content1')"])
expect(PathHelper.getSegments("Root/Example/('Content1')")).toEqual(['Root', 'Example', "('Content1')"])
})

@@ -161,10 +66,6 @@ })

describe('#getParentPath()', () => {
it('Should return the parent path in case of more than 1 segments', () => {
it('Should return the parent path', () => {
expect(PathHelper.getParentPath('Root/Example/Content')).toBe('Root/Example')
})
it('Should return the parent path in case of more than 1 segments with item path', () => {
expect(PathHelper.getParentPath("Root/Example('Content')")).toBe('Root/Example')
})
it('Should return the path in case of 1 segments', () => {

@@ -171,0 +72,0 @@ expect(PathHelper.getParentPath('Root')).toBe('Root')

@@ -25,3 +25,3 @@ /**

* Splits a full path into path segments,
* e.g.: /Root/Example('Content1') will be ["Root", "Example", "('Content1')"]
* e.g.: /Root/Example/stuff
*

@@ -32,81 +32,6 @@ * @param path The path to be splitted

public static getSegments(path: string): string[] {
return path
.split(/\/|[(][']|[(]/g)
.filter((segment) => segment && segment.length)
.map((segment) => {
if (segment.endsWith("')")) {
segment = `('${segment}`
} else if (segment.endsWith(')')) {
segment = `(${segment}`
}
return segment
})
return path.split('/').filter((segment) => segment && segment.length)
}
/**
* Checks if a specific segment is an Item segment or not (like "('Content1')"" or "(654)")
*
* @param segment The segment to be examined
* @returns a boolean value that indicates if the segment is an item segment
*/
public static isItemSegment(segment: string): boolean {
return RegExp(/^\('+[\s\S]+'\)$/).test(segment) || RegExp(/^\(+\d+\)$/).test(segment)
}
/**
* Method that tells if a path is an item path or an item reference path (e.g. contains an Item segment).
*
* @param {string} path Path that you want to test.
* @returns {boolean} Returns if the given path is a path of a Content or not.
*/
public static isItemPath(path: string): boolean {
const segments = this.getSegments(path)
const itemSegment = segments.find((s) => this.isItemSegment(s))
return itemSegment && itemSegment.length ? true : false
}
/**
* Returns the full path for a content based on its Id or Path
*
* @param {string | number} idOrPath the Id Or Path of the content
* @returns A full Id or Path-based url of the content (e.g. *'/content(1)'* or *'/Root/Example/('Content')'*)
*/
public static getContentUrl(idOrPath: string | number): string {
const parsed = parseInt(idOrPath as string, 10)
if (isNaN(parsed)) {
return this.getContentUrlByPath(idOrPath.toString())
} else {
return this.getContentUrlbyId(parsed)
}
}
/**
* Method that gets the URL that refers to a single item in the Sense/Net Content Repository
*
* @param {string} path Path that you want to format.
* @returns {string} Path in entity format e.g. /workspaces('project') from /workspaces/project
*/
public static getContentUrlByPath(path: string): string {
if (!path) {
throw Error('Path is empty')
}
const segments = this.getSegments(path)
if (!this.isItemPath(path)) {
segments[segments.length - 1] = `('${segments[segments.length - 1]}')`
}
return segments.join('/')
}
/**
* Method that gets the URL that refers to a single item in the Sense/Net Content Repository by its Id
*
* @param id {number} Id of the Content.
* @returns {string} e.g. /content(123)
*/
public static getContentUrlbyId(id: number): string {
return `content(${id})`
}
/**
* Method that allows to join paths without multiple or missing slashes

@@ -113,0 +38,0 @@ *

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc