Socket
Socket
Sign inDemoInstall

@washingtonpost/front-end-utils

Package Overview
Dependencies
Maintainers
200
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.14-experimental.1 to 0.2.0

dist/index.d.ts.map

18

dist/index.d.ts

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

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

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

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

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

}
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;
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;
/**

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

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

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

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
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
{
"name": "@washingtonpost/front-end-utils",
"version": "0.1.14-experimental.1",
"version": "0.2.0",
"description": "> TODO: description",

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

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

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

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

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

"dependencies": {
"react": "^16.0.1 || ^17.0.2",
"react-dom": "^16.0.1 || ^17.0.2"
"@babel/runtime": "^7.13.10"
},
"gitHead": "64793cde927a287b6f3726550102d9022472b986",
"devDependencies": {
"tsup": "^5.11.13",
"typescript": "^4.5.5"
}
"parcel": "^2.0.1"
},
"gitHead": "d132f19b46bc1c47df097e989e8bbf1d7281a43c"
}

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