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

@solid-primitives/script-loader

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/script-loader - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

dist/index.cjs

18

dist/index.d.ts

@@ -1,3 +0,13 @@

import { Accessor } from "solid-js";
export declare const createScriptLoader: (opts: {
import { Accessor } from 'solid-js';
/**
* Creates a convenient script loader utility
*
* @param string URL of the script to load.
* @param type Type value to put in the script attribute.
* @param function Callback to trigger onLoad.
* @param function callback on error.
* @returns
*/
declare const createScriptLoader: (opts: {
src: string | Accessor<string>;

@@ -7,2 +17,4 @@ type?: string;

onerror?: () => void;
}) => [script: HTMLScriptElement, remove: () => void];
}) => [script: HTMLScriptElement | undefined, remove: () => void];
export { createScriptLoader };

28

dist/index.js

@@ -0,15 +1,19 @@

// src/index.ts
import { createEffect, onCleanup } from "solid-js";
export const createScriptLoader = (opts) => {
const script = document.createElement("script");
var createScriptLoader = (opts) => {
const script = document.createElement("script");
script.src = typeof opts.src === "function" ? opts.src() : opts.src;
opts.type && (script.type = opts.type);
opts.onload && script.addEventListener("load", opts.onload);
opts.onerror && script.addEventListener("error", opts.onerror);
document.head.appendChild(script);
const remove = () => document.head.removeChild(script);
createEffect(() => {
script.src = typeof opts.src === "function" ? opts.src() : opts.src;
opts.type && (script.type = opts.type);
opts.onload && script.addEventListener("load", opts.onload);
opts.onerror && script.addEventListener("error", opts.onerror);
document.head.appendChild(script);
const remove = () => document.head.removeChild(script);
createEffect(() => {
script.src = typeof opts.src === "function" ? opts.src() : opts.src;
});
onCleanup(remove);
return [script, remove];
});
onCleanup(remove);
return [script, remove];
};
export {
createScriptLoader
};
{
"name": "@solid-primitives/script-loader",
"version": "1.0.1",
"version": "1.0.2",
"description": "Primitive to load scripts dynamically",

@@ -8,20 +8,35 @@ "author": "Alex Lohr <alex.lohr@logmein.com>",

"homepage": "https://github.com/davedbase/solid-primitives/tree/main/packages/script",
"private": false,
"main": "dist/index.js",
"module": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/davedbase/solid-primitives.git"
},
"primitive": {
"name": "script-loader",
"stage": 3,
"list": [
"createScriptLoader"
],
"category": "Utilities"
},
"files": [
"dist"
],
"private": false,
"sideEffects": false,
"type": "module",
"main": "./dist/server.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/cjs/index.js",
"node": {
"import": "./dist/server.js",
"require": "./dist/server.cjs"
},
"import": "./dist/index.js",
"default": "./dist/index.js"
"require": "./dist/index.cjs"
},
"sideEffects": "false",
"scripts": {
"prebuild": "npm run clean",
"clean": "rimraf dist/",
"build": "tsc && tsc --target es5 --module commonjs --declaration false --outDir ./dist/cjs",
"build": "tsup",
"test": "uvu -r solid-register test"

@@ -41,2 +56,3 @@ },

"tslib": "^2.3.1",
"tsup": "^5.10.1",
"typescript": "^4.4.3",

@@ -43,0 +59,0 @@ "uvu": "^0.5.2"

@@ -1,8 +0,1 @@

---
Name: script-loader
Stage: 3
Package: "@solid-primitives/script-loader"
Primitives: createScriptLoader
---
# @solid-primitives/script-loader

@@ -16,2 +9,10 @@

## Installation
```
npm install @solid-primitives/script-loader
# or
yarn add @solid-primitives/script-loader
```
## How to use it

@@ -51,3 +52,3 @@

1.0.1
1.0.2

@@ -54,0 +55,0 @@ Release first first with CJS support.

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