@lwrjs/shared-utils
Advanced tools
Comparing version 0.0.2-alpha1 to 0.0.2-alpha10
/// <reference types="node" /> | ||
import { extractMetadataFromHtml } from './html-meta'; | ||
import { ApplicationMode, ModeConfig, ModuleDefinition, ModuleEntry, ModuleJsonDefinition, ModuleRegistry, RuntimeContext, VirtualModuleEntry } from '@lwrjs/types'; | ||
@@ -9,2 +10,3 @@ interface SpecifierConfig { | ||
export declare function getSpecifier({ namespace, name }: SpecifierConfig): string; | ||
export { extractMetadataFromHtml }; | ||
export declare function explodeSpecifier(specifier: string, defaultNs?: string): [string, string]; | ||
@@ -36,3 +38,41 @@ export declare function explodeName(rawName: string): [string, string | undefined]; | ||
export declare function deepFreeze(obj: any, maxDepth?: number): any; | ||
export {}; | ||
/** | ||
* Returns a function which debounces when the input function is called with the same first argument | ||
* | ||
* @param func - Function to debounce | ||
* @param waitFor - milliseconds to wait between calls | ||
*/ | ||
export declare const debounce: <F extends (...args: any[]) => any>(func: F, waitFor: number) => (...args: Parameters<F>) => ReturnType<F>; | ||
/** | ||
* Turn a string into a slug | ||
* | ||
* @example - 'This IS a sentence' => 'this-is-a-sentence' | ||
* @param name a string to slugify | ||
*/ | ||
export declare function slugify(name: string): string; | ||
/** | ||
* Turn a string into kebab case to camel case | ||
* | ||
* @example - 'name-of-something' => 'name/ofSomething' | ||
* @param name A string in kebab case | ||
*/ | ||
export declare function kebabcaseToCamelcase(name: string): string; | ||
/** | ||
* Clone of lwr/init, reverse of kebabcaseToCamelcase, strips off versions | ||
* | ||
* @example - 'name/ofSomething/v/1.0.0' => 'name-of-something' | ||
* @param specifier | ||
*/ | ||
export declare function moduleSpecifierToKebabCase(specifier: string): string; | ||
/** | ||
* Replace a part of a source string at the indices with a different value | ||
* | ||
* @param src - source string | ||
* @param param1 - offset indices | ||
* @param replaceValue - replacement | ||
*/ | ||
export declare function replaceStringFromLocation(src: string, { startOffset, endOffset }: { | ||
startOffset: number; | ||
endOffset: number; | ||
}, replaceValue: string): string; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,6 +6,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deepFreeze = exports.resolveFileExtension = exports.serializeModuleToJson = exports.isVirtualModuleEntry = exports.readFile = exports.hashContent = exports.normalizeVersionFromUri = exports.normalizeVersionToUri = exports.explodeMode = exports.explodeName = exports.explodeSpecifier = exports.getSpecifier = exports.DEFAULT_NAMESPACE = void 0; | ||
exports.replaceStringFromLocation = exports.moduleSpecifierToKebabCase = exports.kebabcaseToCamelcase = exports.slugify = exports.debounce = exports.deepFreeze = exports.resolveFileExtension = exports.serializeModuleToJson = exports.isVirtualModuleEntry = exports.readFile = exports.hashContent = exports.normalizeVersionFromUri = exports.normalizeVersionToUri = exports.explodeMode = exports.explodeName = exports.explodeSpecifier = exports.extractMetadataFromHtml = exports.getSpecifier = exports.DEFAULT_NAMESPACE = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const slugify_1 = __importDefault(require("slugify")); | ||
const html_meta_1 = require("./html-meta"); | ||
Object.defineProperty(exports, "extractMetadataFromHtml", { enumerable: true, get: function () { return html_meta_1.extractMetadataFromHtml; } }); | ||
exports.DEFAULT_NAMESPACE = 'lwr-lib'; // it must have a dash so its guarantee to not collide | ||
@@ -79,3 +82,2 @@ function getSpecifier({ namespace, name }) { | ||
ownHash, | ||
signature: ownHash, | ||
links: { | ||
@@ -142,2 +144,3 @@ self: moduleRegistry.resolveModuleUri(moduleId, context, ownHash), | ||
exports.resolveFileExtension = resolveFileExtension; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function _deepFreeze(obj, maxDepth, depth) { | ||
@@ -160,2 +163,3 @@ if (depth < maxDepth) { | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function deepFreeze(obj, maxDepth = 5) { | ||
@@ -165,2 +169,87 @@ return _deepFreeze(obj, maxDepth, 0); | ||
exports.deepFreeze = deepFreeze; | ||
/** | ||
* Returns a function which debounces when the input function is called with the same first argument | ||
* | ||
* @param func - Function to debounce | ||
* @param waitFor - milliseconds to wait between calls | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
exports.debounce = (func, waitFor) => { | ||
const timeouts = new Map(); | ||
const debounced = (...args) => { | ||
const firstArg = args[0]; | ||
if (!timeouts.has(firstArg)) { | ||
func(...args); | ||
timeouts.set(args[0], setTimeout(() => { | ||
timeouts.delete(firstArg); | ||
}, waitFor)); | ||
} | ||
}; | ||
return debounced; | ||
}; | ||
/** | ||
* Turn a string into a slug | ||
* | ||
* @example - 'This IS a sentence' => 'this-is-a-sentence' | ||
* @param name a string to slugify | ||
*/ | ||
function slugify(name) { | ||
return slugify_1.default(name, { | ||
lower: true, | ||
}); | ||
} | ||
exports.slugify = slugify; | ||
/** | ||
* Turn a string into kebab case to camel case | ||
* | ||
* @example - 'name-of-something' => 'name/ofSomething' | ||
* @param name A string in kebab case | ||
*/ | ||
function kebabcaseToCamelcase(name) { | ||
const newName = []; | ||
let nsFound = false; | ||
let upper = false; | ||
for (const currChar of name) { | ||
if (currChar === '-') { | ||
if (!nsFound) { | ||
nsFound = true; | ||
newName.push('/'); | ||
} | ||
else { | ||
upper = true; | ||
} | ||
} | ||
else { | ||
newName.push(upper ? currChar.toUpperCase() : currChar); | ||
upper = false; | ||
} | ||
} | ||
return newName.join(''); | ||
} | ||
exports.kebabcaseToCamelcase = kebabcaseToCamelcase; | ||
/** | ||
* Clone of lwr/init, reverse of kebabcaseToCamelcase, strips off versions | ||
* | ||
* @example - 'name/ofSomething/v/1.0.0' => 'name-of-something' | ||
* @param specifier | ||
*/ | ||
function moduleSpecifierToKebabCase(specifier) { | ||
return specifier | ||
.replace(/\/v\/[a-zA-Z0-9-_.]+$/, '') | ||
.replace('/', '-') | ||
.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`); | ||
} | ||
exports.moduleSpecifierToKebabCase = moduleSpecifierToKebabCase; | ||
/** | ||
* Replace a part of a source string at the indices with a different value | ||
* | ||
* @param src - source string | ||
* @param param1 - offset indices | ||
* @param replaceValue - replacement | ||
*/ | ||
function replaceStringFromLocation(src, { startOffset, endOffset }, replaceValue) { | ||
return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length); | ||
} | ||
exports.replaceStringFromLocation = replaceStringFromLocation; | ||
//# sourceMappingURL=index.js.map |
@@ -7,5 +7,15 @@ { | ||
}, | ||
"version": "0.0.2-alpha1", | ||
"types": "build/index.d.ts", | ||
"main": "build/index.js", | ||
"version": "0.0.2-alpha10", | ||
"homepage": "https://lwr.dev/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/salesforce/lwr.git", | ||
"directory": "packages/@lwrjs/shared-utils" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/salesforce/lwr/issues" | ||
}, | ||
"types": "build/types/index.d.ts", | ||
"main": "build/commonjs/index.js", | ||
"module": "build/es/index.js", | ||
"files": [ | ||
@@ -15,3 +25,21 @@ "build/**/*.js", | ||
], | ||
"gitHead": "ae4583dba86a00596d3641f60144d8c1f39a0d78" | ||
"dependencies": { | ||
"parse5-sax-parser": "^6.0.1", | ||
"slugify": "^1.4.5" | ||
}, | ||
"scripts": { | ||
"build": "tsc -b && tsc -p tsconfig.es.json" | ||
}, | ||
"lwc": { | ||
"modules": [ | ||
{ | ||
"name": "lwr/observable", | ||
"path": "build/es/observable.js" | ||
} | ||
], | ||
"expose": [ | ||
"lwr/observable" | ||
] | ||
}, | ||
"gitHead": "cb54d75e833b0ecb269a74ae40da0337a18846c1" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
49205
19
1233
1
0
38
2
3
1
+ Addedparse5-sax-parser@^6.0.1
+ Addedslugify@^1.4.5
+ Addedparse5@6.0.1(transitive)
+ Addedparse5-sax-parser@6.0.1(transitive)
+ Addedslugify@1.6.6(transitive)