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

clientside-require

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clientside-require - npm Package Compare versions

Comparing version 3.7.1 to 3.8.3

2

package.json
{
"name": "clientside-require",
"version": "3.7.1",
"version": "3.8.3",
"description": "require() modules, js, css, html, and json in the browser with as little effort as loading jquery",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -157,23 +157,25 @@

normalize_and_analyze_request_path : function(request, relative_path_root){
var extension_whitelist = ["js", "json", "css", "html"];
/*
analyze request
*/
var is_relative_path = request.indexOf("./") == 0; // then it is a path of form "./somepath", a relative path as defined by node
var orig_request = request;
var is_relative_path_type_1 = request.indexOf("./") == 0; // then it is a path of form "./somepath", a relative path as defined by node
var is_relative_path_type_2 = request.indexOf("../") == 0; // then it is a path of form "../somepath", a relative path as defined by node
var is_relative_path = is_relative_path_type_1 || is_relative_path_type_2;
var is_a_path = request.indexOf("/") > -1; // make sure not node_relative_path
var extension = request.slice(1).split('.').pop(); // slice(1) to skip the first letter - avoids error of assuming extension exists if is_relative_path
var exists_file_extension = extension != request.slice(1); // if the "extension" is the full evaluated string, then there is no extension
var is_a_module = !is_a_path && !exists_file_extension;
var analysis = { // build analysis object
is_relative_path:is_relative_path,
is_a_path:is_a_path,
extension:extension,
exists_file_extension:exists_file_extension,
is_a_module:is_a_module,
}
var exists_valid_extension = exists_file_extension && extension_whitelist.indexOf(extension) > -1; // extension is valid if it is fron the extension whitelist
var is_a_module = !is_a_path;
/*
modify request based on analysis (make assumptions)
*/
if(is_a_path && !exists_file_extension){ // if not a node module (i.e., is a path) and there is no extension,
if(is_a_path && !exists_valid_extension){ // if not a node module (i.e., is a path) and there is no valid extension,
extension = "js"; // then it implies a js file
exists_file_extension = true;
exists_valid_extension = true;
request += ".js";

@@ -185,3 +187,3 @@ // TODO (#11) - sometimes this referes to a directory, how to detect whether directory or file?

if(is_relative_path){ // if its a relative path,
request = request.slice(2); // remove the "./" at the begining
if(is_relative_path_type_1) request = request.slice(2); // remove the "./" at the begining
request = relative_path_root + request; // if relative path, use the relative_path_root to generate an absolute path

@@ -196,2 +198,15 @@ }

/*
build analysis object after all modifications and respond
*/
var analysis = {
orig_request : orig_request,
is_relative_path:is_relative_path,
is_a_path:is_a_path,
extension:extension,
exists_file_extension:exists_file_extension,
exists_valid_extension:exists_valid_extension,
is_a_module:is_a_module,
relative_path_root : relative_path_root,
}
return [request, analysis];

@@ -209,2 +224,3 @@ },

var extension = analysis.extension;
var exists_valid_extension = analysis.exists_valid_extension;
var is_a_module = analysis.is_a_module;

@@ -222,3 +238,3 @@

var base_path = request.substring(0, request.lastIndexOf("/")) + "/"; // get dir from filepath
var main = package_json.main;
var main = (package_json.main)? package_json.main : "index.js"; // if main not defined, its index.js
var path = base_path + main; // generate path based on the "main" data in the package json

@@ -249,3 +265,3 @@ var package_options = package_json["clientside-require"];

})
} else if(is_a_path && ["js", "json", "css", "html"].indexOf(extension) > -1){ // if its an acceptable extension and not defining a module
} else if(is_a_path && exists_valid_extension){ // if its an acceptable extension and not defining a module
var path = request; // since its not defining a module, the request has path information

@@ -271,2 +287,3 @@

console.warn("invalid request : " + request + " from root " + relative_path_root)
console.log(analysis);
return Promise.reject("invalid request");

@@ -273,0 +290,0 @@ } else {

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