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

skynet-mysky-utils

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skynet-mysky-utils - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

.github/workflows/ci.yml

10

.eslintrc.json

@@ -18,11 +18,13 @@ {

"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"no-bitwise": 1,
"jsdoc/require-description": 0,
"@typescript-eslint/no-explicit-any": 1,
"@typescript-eslint/no-non-null-assertion": 1,
"jsdoc/require-description": 1,
"jsdoc/require-param-type": 0,
"jsdoc/require-property-type": 0,
"jsdoc/require-returns-type": 0,
"jsdoc/require-throws": 0
"jsdoc/require-throws": 1
}
}
# Changelog
## [0.3.0]
### Changed
- **[Breaking change]** Path functions return paths as lowercase.
- **[Breaking change]** Path functions return `null` for cases that were previously allowed.
### Removed
- **[Breaking change]** Removed deprecated 'CustomUserIDOptions'.
## [0.2.3]

@@ -4,0 +15,0 @@

@@ -12,10 +12,2 @@ export { getPathDomain, getParentPath, sanitizePath } from "./paths";

};
/**
* Custom options for mySky.userID().
*
* @property [legacyAppID] - Deprecated. The legacy app ID. For compatibility with SkyID.
*/
export declare type CustomUserIDOptions = {
legacyAppID?: string;
};
//# sourceMappingURL=index.d.ts.map

4

dist/paths.d.ts

@@ -7,3 +7,3 @@ /**

*/
export declare function getPathDomain(path: string): string;
export declare function getPathDomain(path: string): string | null;
/**

@@ -22,3 +22,3 @@ * Gets the parent path for the given path.

*/
export declare function sanitizePath(path: string): string;
export declare function sanitizePath(path: string): string | null;
//# sourceMappingURL=paths.d.ts.map

@@ -12,3 +12,14 @@ "use strict";

function getPathDomain(path) {
return path.split("/")[0];
// Sanitize the path.
var sanitizedPath = sanitizePath(path);
if (sanitizedPath === null) {
return null;
}
// Split the string and extract the domain. If there are no slashes, the first
// element will contain the entire string.
var domain = sanitizedPath.split("/")[0];
if (domain === "") {
return null;
}
return domain;
}

@@ -23,10 +34,19 @@ exports.getPathDomain = getPathDomain;

function getParentPath(path) {
path = sanitizePath(path);
var pathArray = path.split("/");
// Sanitize the path.
var sanitizedPath = sanitizePath(path);
if (sanitizedPath === null) {
return null;
}
// Split the path.
var pathArray = sanitizedPath.split("/");
if (pathArray.length <= 1) {
return null;
}
// Get the parent path.
pathArray.pop();
path = pathArray.join("/");
return path;
var parentPath = pathArray.join("/");
if (parentPath === "") {
return null;
}
return parentPath;
}

@@ -41,2 +61,8 @@ exports.getParentPath = getParentPath;

function sanitizePath(path) {
// Trim the path.
path = path.trim();
// Paths starting with a slash are invalid.
if (path.startsWith("/")) {
return null;
}
// Remove trailing slashes.

@@ -46,5 +72,13 @@ path = utils_1.trimSuffix(path, "/");

path = utils_1.removeAdjacentChars(path, "/");
return path;
// Convert the domain to lowercase.
var pathArray = path.split("/");
pathArray[0] = pathArray[0].toLowerCase();
// Get the sanitized path.
var sanitizedPath = pathArray.join("/");
if (sanitizedPath === "") {
return null;
}
return sanitizedPath;
}
exports.sanitizePath = sanitizePath;
//# sourceMappingURL=paths.js.map
/**
* Creates an invisible iframe with the given src and adds it to the page.
*
* @param srcUrl - The URL to use as src for the iframe.
* @param name - The name for the iframe element.
* @returns - The iframe element.
* @throws - Will throw if the iframe could not be created.
*/

@@ -7,5 +12,23 @@ export declare function createIframe(srcUrl: string, name: string): HTMLIFrameElement;

* Creates a full-screen iframe with the given src and adds it to the page.
*
* @param srcUrl - The URL to use as src for the iframe.
* @param name - The name for the iframe element.
* @returns - The iframe element.
* @throws - Will throw if the iframe could not be created.
*/
export declare function createFullScreenIframe(srcUrl: string, name: string): HTMLIFrameElement;
/**
* Ensures that the given string is a URL.
*
* @param url - The given string.
* @returns - The URL.
*/
export declare function ensureUrl(url: string): string;
/**
* Removes duplicate adjacent characters from the given string.
*
* @param str - The given string.
* @param char - The character to remove duplicates of.
* @returns - The string without duplicate adjacent characters.
*/
export declare function removeAdjacentChars(str: string, char: string): string;

@@ -21,2 +44,10 @@ /**

export declare function trimSuffix(str: string, suffix: string, limit?: number): string;
/**
* Prepends the prefix to the given string only if the string does not already start with the prefix.
*
* @param str - The string.
* @param prefix - The prefix.
* @returns - The prefixed string.
*/
export declare function ensurePrefix(str: string, prefix: string): string;
//# sourceMappingURL=utils.d.ts.map
"use strict";
exports.__esModule = true;
exports.trimSuffix = exports.removeAdjacentChars = exports.ensureUrl = exports.createFullScreenIframe = exports.createIframe = void 0;
exports.ensurePrefix = exports.trimSuffix = exports.removeAdjacentChars = exports.ensureUrl = exports.createFullScreenIframe = exports.createIframe = void 0;
/**
* Creates an invisible iframe with the given src and adds it to the page.
*
* @param srcUrl - The URL to use as src for the iframe.
* @param name - The name for the iframe element.
* @returns - The iframe element.
* @throws - Will throw if the iframe could not be created.
*/

@@ -10,2 +15,5 @@ function createIframe(srcUrl, name) {

var childFrame = document.createElement("iframe");
if (childFrame === null) {
throw new Error("Could not create new iframe");
}
childFrame.src = srcUrl;

@@ -24,2 +32,7 @@ childFrame.name = name;

* Creates a full-screen iframe with the given src and adds it to the page.
*
* @param srcUrl - The URL to use as src for the iframe.
* @param name - The name for the iframe element.
* @returns - The iframe element.
* @throws - Will throw if the iframe could not be created.
*/

@@ -29,2 +42,5 @@ function createFullScreenIframe(srcUrl, name) {

var childFrame = document.createElement("iframe");
if (childFrame === null) {
throw new Error("Could not create new iframe");
}
childFrame.src = srcUrl;

@@ -53,2 +69,8 @@ childFrame.name = name;

exports.createFullScreenIframe = createFullScreenIframe;
/**
* Ensures that the given string is a URL.
*
* @param url - The given string.
* @returns - The URL.
*/
function ensureUrl(url) {

@@ -58,2 +80,9 @@ return ensurePrefix(url, "https://");

exports.ensureUrl = ensureUrl;
/**
* Removes duplicate adjacent characters from the given string.
*
* @param str - The given string.
* @param char - The character to remove duplicates of.
* @returns - The string without duplicate adjacent characters.
*/
function removeAdjacentChars(str, char) {

@@ -93,8 +122,16 @@ var pathArray = Array.from(str);

exports.trimSuffix = trimSuffix;
function ensurePrefix(s, prefix) {
if (!s.startsWith(prefix)) {
s = "" + prefix + s;
/**
* Prepends the prefix to the given string only if the string does not already start with the prefix.
*
* @param str - The string.
* @param prefix - The prefix.
* @returns - The prefixed string.
*/
function ensurePrefix(str, prefix) {
if (!str.startsWith(prefix)) {
str = "" + prefix + str;
}
return s;
return str;
}
exports.ensurePrefix = ensurePrefix;
//# sourceMappingURL=utils.js.map

@@ -8,2 +8,4 @@ export declare const errorWindowClosed = "window-closed";

* Checks if there has been an error from the window on an interval.
*
* @returns - The promise that rejects if the listener encounters an error from the remote window, and a controller that can abort the event listener and clean up the promise.
*/

@@ -10,0 +12,0 @@ export declare function monitorWindowError(): {

@@ -17,2 +17,4 @@ "use strict";

* Checks if there has been an error from the window on an interval.
*
* @returns - The promise that rejects if the listener encounters an error from the remote window, and a controller that can abort the event listener and clean up the promise.
*/

@@ -23,5 +25,5 @@ function monitorWindowError() {

var promise = new Promise(function (resolve, reject) {
var handleEvent = function (e) {
var handleEvent = function (event) {
window.removeEventListener(exports.dispatchedErrorEvent, handleEvent);
var err = e.detail;
var err = event.detail;
reject(err);

@@ -28,0 +30,0 @@ };

{
"name": "skynet-mysky-utils",
"version": "0.2.3",
"version": "0.3.0",
"description": "Skynet common MySky utilities",

@@ -9,7 +9,17 @@ "main": "dist/index.js",

"lint": "npm run lint:tsc && npm run lint:eslint",
"lint:eslint": "eslint --ext .ts src",
"lint:eslint": "eslint --ext .ts src --max-warnings 0",
"lint:tsc": "tsc",
"prepare": "husky install",
"prepublishOnly": "npm run build",
"test": "jest"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --max-warnings 0",
"prettier --write"
],
"*.{json,yml,md}": [
"prettier --write"
]
},
"jest": {

@@ -43,7 +53,9 @@ "rootDir": "src"

"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "^7.21.0",
"eslint-plugin-jsdoc": "^32.2.0",
"husky": "^7.0.1",
"jest": "^26.6.3",
"lint-staged": "^11.0.0",
"prettier": "^2.2.1",

@@ -50,0 +62,0 @@ "rimraf": "^3.0.2",

@@ -37,10 +37,1 @@ export { getPathDomain, getParentPath, sanitizePath } from "./paths";

};
/**
* Custom options for mySky.userID().
*
* @property [legacyAppID] - Deprecated. The legacy app ID. For compatibility with SkyID.
*/
export type CustomUserIDOptions = {
legacyAppID?: string;
};
import { getParentPath, getPathDomain, sanitizePath } from "./paths";
describe("getPathDomain", () => {
const paths = [
const paths: Array<[string, string | null]> = [
["path.hns", "path.hns"],
["path.hns/path", "path.hns"],
["path.hns//path/path/", "path.hns"],
["PATH.Hns//Path/path/", "path.hns"],
["/path/file/", null],
["", null],
];
it.each(paths)("domain for path %s should be %s", (path, pathDomain) => {
it.each(paths)("domain for path '%s' should be '%s'", (path, pathDomain) => {
const receivedDomain = getPathDomain(path);

@@ -19,8 +23,13 @@ expect(receivedDomain).toEqual(pathDomain);

["app.hns///path///file.json", "app.hns/path"],
["APP.hns///Path///file.json", "app.hns/Path"],
["app.hns//path", "app.hns"],
["app.hns/path/", "app.hns"],
["/app.hns/path/", null],
["app.hns//", null],
["//app.hns//", null],
["//", null],
["", null],
];
it.each(paths)("parent path for %s should be %s", (path, parentPath) => {
it.each(paths)("parent path for '%s' should be '%s'", (path, parentPath) => {
const receivedPath = getParentPath(path);

@@ -32,11 +41,22 @@ expect(receivedPath).toEqual(parentPath);

describe("sanitizePath", () => {
const paths = [
const paths: Array<[string, string | null]> = [
["test.hns", "test.hns"],
[" test.hns ", "test.hns"],
["path.hns", "path.hns"],
["Path.HNS", "path.hns"],
["//path/file/", null],
["\t//path/file/", null],
["path.hns//file.json//", "path.hns/file.json"],
["PATH.Hns//File.json//", "path.hns/File.json"],
["//", null],
["", null],
];
it.each(paths)("path %s should be sanitized to %s", (path, sanitizedPath) => {
const receivedPath = sanitizePath(path);
expect(receivedPath).toEqual(sanitizedPath);
});
it.each(paths)(
"path '%s' should be sanitized to '%s'",
(path, sanitizedPath) => {
const receivedPath = sanitizePath(path);
expect(receivedPath).toEqual(sanitizedPath);
}
);
});

@@ -9,4 +9,16 @@ import { removeAdjacentChars, trimSuffix } from "./utils";

*/
export function getPathDomain(path: string): string {
return path.split("/")[0];
export function getPathDomain(path: string): string | null {
// Sanitize the path.
const sanitizedPath = sanitizePath(path);
if (sanitizedPath === null) {
return null;
}
// Split the string and extract the domain. If there are no slashes, the first
// element will contain the entire string.
const [domain] = sanitizedPath.split("/");
if (domain === "") {
return null;
}
return domain;
}

@@ -21,5 +33,10 @@

export function getParentPath(path: string): string | null {
path = sanitizePath(path);
const pathArray = path.split("/");
// Sanitize the path.
const sanitizedPath = sanitizePath(path);
if (sanitizedPath === null) {
return null;
}
// Split the path.
const pathArray = sanitizedPath.split("/");
if (pathArray.length <= 1) {

@@ -29,5 +46,9 @@ return null;

// Get the parent path.
pathArray.pop();
path = pathArray.join("/");
return path;
const parentPath = pathArray.join("/");
if (parentPath === "") {
return null;
}
return parentPath;
}

@@ -41,3 +62,11 @@

*/
export function sanitizePath(path: string): string {
export function sanitizePath(path: string): string | null {
// Trim the path.
path = path.trim();
// Paths starting with a slash are invalid.
if (path.startsWith("/")) {
return null;
}
// Remove trailing slashes.

@@ -49,3 +78,12 @@ path = trimSuffix(path, "/");

return path;
// Convert the domain to lowercase.
const pathArray = path.split("/");
pathArray[0] = pathArray[0].toLowerCase();
// Get the sanitized path.
const sanitizedPath = pathArray.join("/");
if (sanitizedPath === "") {
return null;
}
return sanitizedPath;
}
/**
* Creates an invisible iframe with the given src and adds it to the page.
*
* @param srcUrl - The URL to use as src for the iframe.
* @param name - The name for the iframe element.
* @returns - The iframe element.
* @throws - Will throw if the iframe could not be created.
*/

@@ -7,3 +12,6 @@ export function createIframe(srcUrl: string, name: string): HTMLIFrameElement {

const childFrame = document.createElement("iframe")!;
const childFrame = document.createElement("iframe");
if (childFrame === null) {
throw new Error("Could not create new iframe");
}
childFrame.src = srcUrl;

@@ -24,2 +32,7 @@ childFrame.name = name;

* Creates a full-screen iframe with the given src and adds it to the page.
*
* @param srcUrl - The URL to use as src for the iframe.
* @param name - The name for the iframe element.
* @returns - The iframe element.
* @throws - Will throw if the iframe could not be created.
*/

@@ -32,3 +45,6 @@ export function createFullScreenIframe(

const childFrame = document.createElement("iframe")!;
const childFrame = document.createElement("iframe");
if (childFrame === null) {
throw new Error("Could not create new iframe");
}
childFrame.src = srcUrl;

@@ -60,2 +76,8 @@ childFrame.name = name;

/**
* Ensures that the given string is a URL.
*
* @param url - The given string.
* @returns - The URL.
*/
export function ensureUrl(url: string): string {

@@ -65,2 +87,9 @@ return ensurePrefix(url, "https://");

/**
* Removes duplicate adjacent characters from the given string.
*
* @param str - The given string.
* @param char - The character to remove duplicates of.
* @returns - The string without duplicate adjacent characters.
*/
export function removeAdjacentChars(str: string, char: string): string {

@@ -103,7 +132,14 @@ const pathArray = Array.from(str);

function ensurePrefix(s: string, prefix: string): string {
if (!s.startsWith(prefix)) {
s = `${prefix}${s}`;
/**
* Prepends the prefix to the given string only if the string does not already start with the prefix.
*
* @param str - The string.
* @param prefix - The prefix.
* @returns - The prefixed string.
*/
export function ensurePrefix(str: string, prefix: string): string {
if (!str.startsWith(prefix)) {
str = `${prefix}${str}`;
}
return s;
return str;
}

@@ -5,3 +5,3 @@ export const errorWindowClosed = "window-closed";

export class PromiseController {
cleanup() {
cleanup(): void {
// Empty until implemented in monitorWindowError.

@@ -13,2 +13,4 @@ }

* Checks if there has been an error from the window on an interval.
*
* @returns - The promise that rejects if the listener encounters an error from the remote window, and a controller that can abort the event listener and clean up the promise.
*/

@@ -23,6 +25,6 @@ export function monitorWindowError(): {

const promise: Promise<void> = new Promise((resolve, reject) => {
const handleEvent = function (e: any) {
const handleEvent = function (event: Event) {
window.removeEventListener(dispatchedErrorEvent, handleEvent);
const err = e.detail;
const err = (<CustomEvent>event).detail;
reject(err);

@@ -29,0 +31,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

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