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

@washingtonpost/front-end-utils

Package Overview
Dependencies
Maintainers
199
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@washingtonpost/front-end-utils - npm Package Compare versions

Comparing version 0.1.13 to 0.1.14-experimental.0

dist/index.mjs

18

dist/index.d.ts

@@ -10,3 +10,4 @@ /**

*/
export const slugify: (str: string) => string;
declare const slugify: (str: string) => string;
/**

@@ -30,3 +31,4 @@ *

*/
export const getClasses: (defaultClassNames?: string, conditionalClassNames?: object) => string;
declare const getClasses: (defaultClassNames?: string, conditionalClassNames?: object) => string;
interface JSONFetchOptions {

@@ -38,5 +40,7 @@ method?: string;

}
export const JSONFetch: (url: string, options: JSONFetchOptions) => Promise<any>;
export const getCookie: (name: string) => string | null | undefined;
export const setCookie: (cookieName: string, cookieValue: string, domainScoped?: boolean) => void;
declare const JSONFetch: (url: string, options: JSONFetchOptions) => Promise<() => any>;
declare const getCookie: (name: string) => string | null | undefined;
declare const setCookie: (cookieName: string, cookieValue: string, domainScoped?: boolean) => void;
/**

@@ -57,4 +61,4 @@ * @function urlSearchParams

*/
export const urlSearchParams: (inputString: string) => object;
declare const urlSearchParams: (inputString: string) => object;
//# sourceMappingURL=index.d.ts.map
export { JSONFetch, getClasses, getCookie, setCookie, slugify, urlSearchParams };

@@ -1,168 +0,2 @@

function $parcel$exportWildcard(dest, source) {
Object.keys(source).forEach(function(key) {
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
return;
}
Object.defineProperty(dest, key, {
enumerable: true,
get: function get() {
return source[key];
}
});
});
return dest;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
var $743ab41c6a89003d$exports = {};
$parcel$export($743ab41c6a89003d$exports, "slugify", () => $743ab41c6a89003d$export$c383cdd2a518017a);
const $743ab41c6a89003d$export$c383cdd2a518017a = (str)=>{
return str.replace(/[,.]/g, "").replace(/&/g, "and").replace(/\s/g, "-").toLowerCase();
};
var $8567756b9963da7b$exports = {};
$parcel$export($8567756b9963da7b$exports, "getClasses", () => $8567756b9963da7b$export$aeca4cd84e0bb2a4);
const $8567756b9963da7b$export$aeca4cd84e0bb2a4 = (defaultClassNames = "", conditionalClassNames = {
})=>{
let classes = defaultClassNames;
Object.entries(conditionalClassNames).forEach(([classname, shouldApply])=>{
if (shouldApply) classes += ` ${classname}`;
});
return classes.trim();
};
var $b83bf0bfeedef033$exports = {};
$parcel$export($b83bf0bfeedef033$exports, "JSONFetch", () => $b83bf0bfeedef033$export$bfaa87cc2b741d31);
const $b83bf0bfeedef033$export$bfaa87cc2b741d31 = (url, options)=>{
return fetch(url, {
...options,
headers: {
...options.headers,
Accept: "application/json",
"Content-Type": "application/json"
}
}).then((response)=>new Promise((resolve)=>response.json().then((json)=>resolve({
status: response.status,
ok: response.ok,
json: json
})
)
)
).then((response)=>{
// Handles fetch responses, this only checks whether the response is ok or not.
if (!response.ok) throw response.json || response;
return response.json;
});
};
var $43f3fb8dd469cf67$exports = {};
$parcel$export($43f3fb8dd469cf67$exports, "getCookie", () => $43f3fb8dd469cf67$export$4be65e66cfa2648a);
$parcel$export($43f3fb8dd469cf67$exports, "setCookie", () => $43f3fb8dd469cf67$export$110700823644f4a6);
const $43f3fb8dd469cf67$export$4be65e66cfa2648a = (name)=>{
if (typeof window === "undefined") return undefined;
const v = document.cookie.match(`(^|;) ?${name}=([^;]*)(;|$)`);
return v ? v[2] : null;
};
const $43f3fb8dd469cf67$export$110700823644f4a6 = (cookieName, cookieValue, domainScoped = false)=>{
document.cookie = `${cookieName}=${cookieValue};` + (domainScoped && `domain=.${window.origin.split(".").slice(-2).join(".")}; path=/;`);
};
var $7a4517e9cab7772a$exports = {};
$parcel$export($7a4517e9cab7772a$exports, "urlSearchParams", () => $7a4517e9cab7772a$export$42e9e2520bc0a8a6);
const $7a4517e9cab7772a$export$42e9e2520bc0a8a6 = (inputString)=>{
const dict = [];
let search = inputString;
if (inputString.includes("?")) search = inputString.slice(1);
const pairs = search.split("&");
pairs.forEach((pair)=>{
const [name = false, val = false] = pair.split("=");
dict.push({
name: name,
val: val
});
});
/**
* Finds a value in the search params
* @function get
* @param {string} name
* @example
* const queryString = window.location.search;
* const urlParams = urlSearchParams(queryString);
* if (urlParams.get("storyUrl")) {
* setNextUrl(encodeURIComponent(urlParams.get("storyUrl")));
* } else {
* setNextUrl(encodeURIComponent(window.location.href));
* }
*/ function find(input) {
try {
return dict.find((item)=>{
return item.name === input;
});
} catch (error) {
console.error(error);
}
}
/**
* Gets a value from the search params
* @function get
* @param {string} name
* @example
* const queryString = window.location.search;
* const urlParams = urlSearchParams(queryString);
* if (urlParams.get("storyUrl")) {
* setNextUrl(encodeURIComponent(urlParams.get("storyUrl")));
* } else {
* setNextUrl(encodeURIComponent(window.location.href));
* }
* @returns {string}
* @returns {boolean}
*/ function get(input) {
const found = find(input);
if (found) return found.val;
return false;
}
/**
* Checks if a value exists in the search params
* @function has
* @param {string} name
* @example
* const queryString = window.location.search;
* const urlParams = urlSearchParams(queryString);
* if (urlParams.has("storyUrl")) {
* setNextUrl(encodeURIComponent(urlParams.get("storyUrl")));
* } else {
* setNextUrl(encodeURIComponent(window.location.href));
* }
* @returns {boolean}
*/ function has(input) {
const found = find(input);
if (found) return input === found.name;
return false;
}
return {
get: get,
has: has
};
};
$parcel$exportWildcard(module.exports, $743ab41c6a89003d$exports);
$parcel$exportWildcard(module.exports, $8567756b9963da7b$exports);
$parcel$exportWildcard(module.exports, $b83bf0bfeedef033$exports);
$parcel$exportWildcard(module.exports, $43f3fb8dd469cf67$exports);
$parcel$exportWildcard(module.exports, $7a4517e9cab7772a$exports);
//# sourceMappingURL=index.js.map
var c=Object.defineProperty,x=Object.defineProperties,y=Object.getOwnPropertyDescriptor,j=Object.getOwnPropertyDescriptors,b=Object.getOwnPropertyNames,l=Object.getOwnPropertySymbols;var u=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var g=(t,e,n)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p=(t,e)=>{for(var n in e||(e={}))u.call(e,n)&&g(t,n,e[n]);if(l)for(var n of l(e))k.call(e,n)&&g(t,n,e[n]);return t},f=(t,e)=>x(t,j(e)),w=t=>c(t,"__esModule",{value:!0});var O=(t,e)=>{for(var n in e)c(t,n,{get:e[n],enumerable:!0})},$=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of b(e))!u.call(t,o)&&(n||o!=="default")&&c(t,o,{get:()=>e[o],enumerable:!(s=y(e,o))||s.enumerable});return t};var C=(t=>(e,n)=>t&&t.get(e)||(n=$(w({}),e,1),t&&t.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var R={};O(R,{JSONFetch:()=>N,getClasses:()=>J,getCookie:()=>v,setCookie:()=>S,slugify:()=>F,urlSearchParams:()=>E});var F=t=>t.replace(/[,.]/g,"").replace(/&/g,"and").replace(/\s/g,"-").toLowerCase();var J=(t="",e={})=>{let n=t;return Object.entries(e).forEach(([s,o])=>{o&&(n+=` ${s}`)}),n.trim()};var N=async(t,e)=>{let s=await(await fetch(t,f(p({},e),{headers:f(p({},e.headers),{Accept:"application/json","Content-Type":"application/json"})}))).json();if(!s.ok)throw s.json||s;return s.json};var v=t=>{if(typeof window>"u")return;let e=document.cookie.match(`(^|;) ?${t}=([^;]*)(;|$)`);return e?e[2]:null},S=(t,e,n=!1)=>{document.cookie=`${t}=${e};`+(n&&`domain=.${window.origin.split(".").slice(-2).join(".")}; path=/;`)};var E=t=>{let e=[],n=t;t.includes("?")&&(n=t.slice(1)),n.split("&").forEach(i=>{let[r=!1,m=!1]=i.split("=");e.push({name:r,val:m})});function o(i){try{return e.find(r=>r.name===i)}catch(r){console.error(r)}}function d(i){let r=o(i);return r?r.val:!1}function h(i){let r=o(i);return r?i===r.name:!1}return{get:d,has:h}};module.exports=C(R);0&&(module.exports={JSONFetch,getClasses,getCookie,setCookie,slugify,urlSearchParams});
//# sourceMappingURL=index.js.map
{
"name": "@washingtonpost/front-end-utils",
"version": "0.1.13",
"version": "0.1.14-experimental.0",
"description": "> TODO: description",

@@ -10,3 +10,3 @@ "author": "artmsilva <artmsilva@gmail.com>",

"main": "dist/index.js",
"module": "dist/index.module.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",

@@ -24,3 +24,3 @@ "files": [

"test": "echo \"Error: run tests from root\" && exit 1",
"build": "npx parcel build src/index.ts --log-level verbose --no-cache"
"build": "tsup src/index.ts --minify --format esm,cjs --dts --sourcemap"
},

@@ -35,8 +35,10 @@ "bugs": {

"dependencies": {
"@babel/runtime": "^7.13.10"
"react": "^16.0.1 || ^17.0.2",
"react-dom": "^16.0.1 || ^17.0.2"
},
"gitHead": "90fa6e27daf1787e36a85fd902163f4616d7dff3",
"devDependencies": {
"parcel": "^2.0.1"
},
"gitHead": "5fb64bb04eb45e5e39d2a955c714c40bd55645af"
"tsup": "^5.11.13",
"typescript": "^4.5.5"
}
}

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