New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mighty-justice/utils

Package Overview
Dependencies
Maintainers
6
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mighty-justice/utils - npm Package Compare versions

Comparing version 1.4.3 to 1.5.0

dist/objects.d.ts

22

dist/formatting.d.ts

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

/// <reference types="react" />
import React from 'react';
import { IAddress } from './interfaces';

@@ -7,3 +7,3 @@ export declare function canReplaceSymbols(template: string, chars: string[]): boolean;

export declare function hasStringOrNumberContent(value: unknown): value is number | string;
export declare function splitName(name?: string | null): string[];
export declare function splitName(name?: string | null): [string, string];
export declare function splitCommaList(str?: string | null): string[];

@@ -18,4 +18,4 @@ export declare function formatFullName(firstName?: string, lastName?: string): string;

defaultValue?: string;
}): any;
export declare function getOrDefault(value?: unknown): unknown;
}): string;
export declare function getOrDefault(value?: unknown): string;
export declare function formatSocialSecurityNumber(value?: null | string): string;

@@ -26,11 +26,11 @@ export declare function formatEmployerIdNumber(value?: null | string): string;

export declare function formatDollars(value?: null | number | string): string;
export declare function formatParagraphs(value?: null | string): "--" | JSX.Element[];
export declare function formatParagraphs(value?: null | string): string | React.ReactNode[];
export declare function formatCommaSeparatedNumber(value?: null | number | string): string;
export declare function formatDelimitedList(list?: null | string[], delimiter?: string): unknown;
export declare function formatDelimitedList(list?: null | string[], delimiter?: string): string;
export declare function mapBooleanToText(bool?: boolean | null, { mapUndefinedToNo }?: {
mapUndefinedToNo: boolean;
}): "--" | "Yes" | "No";
}): string;
export declare function formatMoneyInput(value?: null | number | string): number;
export declare function formatDuration(iso8601?: null | string): string;
export declare function formatWebsite(website?: string | null, text?: string): string | JSX.Element;
export declare function formatWebsite(website?: string | null, text?: string): React.ReactNode;
export declare function stripNonAlpha(str?: string | null): string;

@@ -40,3 +40,3 @@ export declare function pluralize(baseWord: string, pluralSuffix: string, count: number): string;

export declare function preserveNewLines(body: string): string;
export declare function parseAndPreserveNewlines(body?: string): any;
export declare function parseAndPreserveNewlines(body?: string): React.ReactNode;
export declare function getDisplayName(component: any): string | undefined;

@@ -49,3 +49,3 @@ export declare const varToLabel: (str: string) => string;

export declare function formatAddress(address?: IAddress | null): string;
export declare function formatAddressMultiline(address?: IAddress | null): any;
export declare function stringToHTML(string: string): any;
export declare function formatAddressMultiline(address?: IAddress | null): React.ReactNode;
export declare function stringToHTML(string: string): React.ReactNode;

@@ -7,1 +7,2 @@ export * from './constants';

export * from './validation';
export * from './objects';

@@ -46,5 +46,26 @@ 'use strict';

if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {

@@ -211,15 +232,11 @@ subClass.prototype = Object.create(superClass.prototype);

function getOrDefault(value) {
var isUndefined = value === undefined,
isNull = value === null,
isEmptyString = lodash.isString(value) && !hasStringContent(value);
if (isUndefined || isNull || isEmptyString) {
return EMPTY_FIELD;
if (hasStringContent(value)) {
return value.trim();
}
if (lodash.isString(value)) {
return value.trim();
if (lodash.isNumber(value)) {
return String(value);
}
return value;
return EMPTY_FIELD;
}

@@ -410,6 +427,6 @@ function formatSocialSecurityNumber(value) {

var MAX_CHARS = 3,
prefix = value.split(',')[0] || '',
prefix = value.split(',')[0],
formatted = lodash.startCase(prefix),
isValueAllCaps = formatted === lodash.upperCase(formatted),
wordArray = formatted.match(RE_WORDS) || [];
wordArray = formatted.match(RE_WORDS);
return wordArray.map(function (word) {

@@ -598,2 +615,59 @@ var isWordAllCaps = word === lodash.upperCase(word);

function mergeObjects(objectA, objectB) {
return _extends({}, objectA, objectB);
}
var _hasUnflattenedValues = function _hasUnflattenedValues(value) {
return (lodash.isArray(value) || lodash.isPlainObject(value)) && !!Object.keys(value).length;
};
function _flattenObject(input, parentKey) {
var _getFlatKey = function _getFlatKey(key) {
if (lodash.isArray(input)) {
return parentKey + "[" + key + "]";
}
if (parentKey) {
return parentKey + "." + key;
}
return key;
};
return Object.entries(input).reduce(function (output, _ref) {
var _mergeObjects;
var key = _ref[0],
value = _ref[1];
var flatKey = _getFlatKey(key);
if (_hasUnflattenedValues(value)) {
var flatValues = _flattenObject(value, flatKey);
return mergeObjects(output, flatValues);
}
return mergeObjects(output, (_mergeObjects = {}, _mergeObjects[flatKey] = value, _mergeObjects));
}, {});
}
function flattenObject(input) {
return _flattenObject(input, '');
}
function unflattenObject(object) {
return Object.entries(flattenObject(object)).reduce(function (objOut, _ref2) {
var key = _ref2[0],
value = _ref2[1];
return lodash.set(objOut, key, value);
}, {});
}
Object.defineProperty(exports, 'flattenArray', {
enumerable: true,
get: function () {
return lodash.flatten;
}
});
exports.CENT_DECIMAL = CENT_DECIMAL;

@@ -609,2 +683,3 @@ exports.DATE_FORMATS = DATE_FORMATS;

exports.dateToday = dateToday;
exports.flattenObject = flattenObject;
exports.formatAddress = formatAddress;

@@ -652,3 +727,4 @@ exports.formatAddressMultiline = formatAddressMultiline;

exports.toKey = toKey;
exports.unflattenObject = unflattenObject;
exports.varToLabel = varToLabel;
//# sourceMappingURL=utils.cjs.development.js.map

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

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("decimal.js")),t=require("tslib"),n=require("react"),o=e(n),i=require("mobx"),a=require("mobx-react"),u=e(require("classnames")),s=require("iso8601-duration"),p=require("date-fns"),f=e(require("numeral")),c=e(require("html-react-parser")),l=e(require("fast-memoize")),m=require("lodash"),d=e(require("moment")),v={date:"LL/dd/yy",date_at_time:"LL/dd/yy @ h:mma",date_value:"yyyy-LL-dd"},x=new r("100"),b=/[^A-Za-z]/g,y=/[A-Za-z0-9\u00C0-\u00FF+]+[^\s-]*/g,g=/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;function h(e,r){e.prototype=Object.create(r.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function C(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _(e,r){return e.split("#").length-1===r.length}function S(e,r){var t=r.reverse();return e.split("").map((function(e){return"#"===e?t.pop():e})).join("")}function D(e){return!!m.isString(e)&&!!e.replace(/ /g,"").length}function N(e){return D(e)||m.isNumber(e)}function j(e,r){if(!D(e))return"--";var t=e.match(/\d/g)||[];if((e.match(/[^0-9\-(). ]/g)||[]).length)return e;for(var n,o=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return C(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?C(e,void 0):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(n=o()).done;){var i=n.value;if(_(i,t))return S(i,t)}return e}function A(e,r){return void 0===r&&(r=v.date),D(e)?p.format(p.parseISO(e),r):"--"}function O(e){var r=void 0===e,t=null===e,n=m.isString(e)&&!D(e);return r||t||n?"--":m.isString(e)?e.trim():e}function L(e){return e.replace(/\n/g,"<br/>")}function T(e){if(e)return e.displayName||e.name||"Component"}function w(e){return e.search(g)>-1}function P(e){var r=e.split(".").pop()||"",t=m.startCase(r).match(y)||[],n=t.length>1;return t.map((function(e,r){return r>0&&n&&w(e)?e.toLowerCase():e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})).join(" ")}var q=l(P);function E(e){if(!e)return"--, --, -- --";var r=m.mapValues(e,(function(e){return e||"--"})),t=r.city,n=r.state,o=r.zip_code;return[r.address1,e.address2].join(" ").trim()+", "+t+", "+n+" "+o}function I(){return A((new Date).toISOString(),v.date_value)}function M(e){return new Date(e).getTime()>new Date((new Date).toDateString()).getTime()}function R(e){return m.isString(e)&&""!==e||m.isNumber(e)||r.isDecimal(e)}function U(e){return!e||e.length==="####-##-##".length&&d(e).isValid()}exports.CENT_DECIMAL=x,exports.DATE_FORMATS=v,exports.EMPTY_FIELD="--",exports.RE_ALPHA=b,exports.RE_SMALL_WORDS=g,exports.RE_WORDS=y,exports.canReplaceSymbols=_,exports.createDisabledContainer=function(e){var r=function(r){function t(){return r.apply(this,arguments)||this}return h(t,r),t.prototype.render=function(){var r=u(this.props.className,"disabled");return o.createElement(e,Object.assign({},this.props,{className:r,"data-for":"permission-required","data-tip":!0,"data-tip-disable":!1,onClick:null,onSelect:null}))},t}(n.Component);return r.displayName="DisabledContainer("+T(e)+")",t.__decorate([a.observer],r)},exports.createGuardedContainer=function(e){var r=e.isGuarded,u=e.enabledComponent,s=e.disabledComponent,p=function(e){function t(r){var t;return(t=e.call(this,r)||this).GuardedComponent=t.userHasPermission?u:s,t}var n;return h(t,e),t.prototype.render=function(){return o.createElement(this.GuardedComponent,Object.assign({},this.props))},(n=[{key:"userHasPermission",get:function(){return!r}}])&&function(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(t.prototype,n),t}(n.Component);return p.displayName="GuardedContainer("+T(u)+")",t.__decorate([i.computed],p.prototype,"userHasPermission",null),t.__decorate([a.observer],p)},exports.dateToday=I,exports.formatAddress=E,exports.formatAddressMultiline=function(e){return c(E(e).replace(", ","<br/>"))},exports.formatCommaSeparatedNumber=function(e){return N(e)?f(e).format("0,0"):"--"},exports.formatDate=A,exports.formatDateTime=function(e){return A(e,v.date_at_time)},exports.formatDelimitedList=function(e,r){return void 0===r&&(r=", "),e?O(e.join(r)):"--"},exports.formatDollars=function(e){return N(e)?f(e).format("$0,0"):"--"},exports.formatDuration=function(e){if(!D(e))return"--";var r=Object.entries(s.parse(e));return(r=r.filter((function(e){return e[1]>0}))).map((function(e){var r=e[0],t=e[1];return[1===t?r.slice(0,-1):r,t]})).map((function(e){return e[1]+" "+e[0]})).join(", ")},exports.formatEmployerIdNumber=function(e){return j(e,["##-#######"])},exports.formatFullName=function(e,r){return((e||"")+" "+(r||"")).trim()},exports.formatMoney=function(e){return N(e)?f(e).format("$0,0.00"):"--"},exports.formatMoneyInput=function(e){return N(e)?f(e).value():e},exports.formatNumberTemplates=j,exports.formatParagraphs=function(e){return D(e)?e.split(/\r?\n/).map((function(e,r){return o.createElement("p",{key:r},e)})):"--"},exports.formatPercentage=function(e,r){if(void 0===r&&(r=2),!N(e))return"--";var t="0."+m.times(r,(function(){return"0"})).join("")+"%";return f(e).format(t)},exports.formatPhoneNumber=function(e){return j(e,["###-####","(###) ###-####","+# (###) ###-####","+## (###) ###-####"])},exports.formatSocialSecurityNumber=function(e){return j(e,["####","###-##-####"])},exports.formatWebsite=function(e,r){return D(e)?o.createElement("a",{href:e,rel:"noopener noreferrer",target:"_blank"},r||e):"--"},exports.getDisplayName=T,exports.getInitials=function(e){if(!D(e))return"";var r=e.split(",")[0]||"",t=m.startCase(r),n=t===m.upperCase(t);return(t.match(y)||[]).map((function(e){var r=e===m.upperCase(e);return w(e)?"":r&&!n?e:e.charAt(0).toUpperCase()})).join("").substring(0,3)},exports.getNameOrDefault=function(e,r){var t=void 0===r?{}:r,n=t.field,o=void 0===n?"name":n,i=t.defaultValue,a=void 0===i?"--":i;if(e){if(m.has(e,"first_name"))return(m.result(e,"first_name","")+" "+m.result(e,"last_name","")).trim();if(m.has(e,o))return m.get(e,o)}return a},exports.getOrDefault=O,exports.getPercentDisplay=function(e){return R(e)?new r(e).times(x).toString():""},exports.getPercentValue=function(e){return R(e)?new r(e).div(x).toString():""},exports.getType=function(e){return e&&e.split(".")[1]||e},exports.hasStringContent=D,exports.hasStringOrNumberContent=N,exports.inferCentury=function(e){if(2!==e.length)return e;var r=""+I().substr(0,2)+e,t=""+d().subtract(100,"years").format("YYYY").substr(0,2)+e;return M(r+"-01-01")?t:r},exports.insertIf=function(e,r){return e?[r]:[]},exports.isFutureDate=M,exports.isValidDate=U,exports.isValidPastDate=function(e){return!e||U(e)&&d(e).isBefore(d())},exports.mapBooleanToText=function(e,r){var t=(void 0===r?{mapUndefinedToNo:!1}:r).mapUndefinedToNo;return m.isBoolean(e)?e?"Yes":"No":t&&void 0===e?"No":"--"},exports.parseAndPreserveNewlines=function(e){return D(e)?c(L(m.escape(e))):"--"},exports.pluralize=function(e,r,t){return 1===t?e:""+e+r},exports.preserveNewLines=L,exports.replaceSymbolsWithChars=S,exports.splitCommaList=function(e){return D(e)?-1===e.indexOf(",")?[e.trim()]:e.split(",").map((function(e){return e.trim()})).filter((function(e){return""!==e})):[]},exports.splitName=function(e){if(!D(e))return["",""];var r=e.trim().split(" ");return[r[0],r.slice(1).join(" ").trim()]},exports.stringToHTML=function(e){return c(e)},exports.stripNonAlpha=function(e){return D(e)?e.replace(b,""):""},exports.toKey=function(e){var r=m.sortBy(m.map(e,(function(e,r){return[r,e]}))),t=m.reject(r,(function(e){return null==e[1]}));return t.length<1?"":"?"+t.map((function(e){var r=e[1];return encodeURIComponent(e[0])+"="+encodeURIComponent(r)})).join("&")},exports.varToLabel=q;
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("decimal.js")),t=require("tslib"),n=require("react"),o=e(n),i=require("mobx"),a=require("mobx-react"),u=e(require("classnames")),s=require("iso8601-duration"),p=require("date-fns"),c=e(require("numeral")),f=e(require("html-react-parser")),l=e(require("fast-memoize")),m=require("lodash"),d=e(require("moment")),b={date:"LL/dd/yy",date_at_time:"LL/dd/yy @ h:mma",date_value:"yyyy-LL-dd"},y=new r("100"),v=/[^A-Za-z]/g,x=/[A-Za-z0-9\u00C0-\u00FF+]+[^\s-]*/g,g=/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;function h(){return(h=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function j(e,r){e.prototype=Object.create(r.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function C(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function O(e,r){return e.split("#").length-1===r.length}function _(e,r){var t=r.reverse();return e.split("").map((function(e){return"#"===e?t.pop():e})).join("")}function N(e){return!!m.isString(e)&&!!e.replace(/ /g,"").length}function S(e){return N(e)||m.isNumber(e)}function D(e,r){if(!N(e))return"--";var t=e.match(/\d/g)||[];if((e.match(/[^0-9\-(). ]/g)||[]).length)return e;for(var n,o=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return C(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?C(e,void 0):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(n=o()).done;){var i=n.value;if(O(i,t))return _(i,t)}return e}function A(e,r){return void 0===r&&(r=b.date),N(e)?p.format(p.parseISO(e),r):"--"}function P(e){return N(e)?e.trim():m.isNumber(e)?String(e):"--"}function L(e){return e.replace(/\n/g,"<br/>")}function T(e){if(e)return e.displayName||e.name||"Component"}function w(e){return e.search(g)>-1}function q(e){var r=e.split(".").pop()||"",t=m.startCase(r).match(x)||[],n=t.length>1;return t.map((function(e,r){return r>0&&n&&w(e)?e.toLowerCase():e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})).join(" ")}var E=l(q);function I(e){if(!e)return"--, --, -- --";var r=m.mapValues(e,(function(e){return e||"--"})),t=r.city,n=r.state,o=r.zip_code;return[r.address1,e.address2].join(" ").trim()+", "+t+", "+n+" "+o}function M(){return A((new Date).toISOString(),b.date_value)}function R(e){return new Date(e).getTime()>new Date((new Date).toDateString()).getTime()}function U(e){return m.isString(e)&&""!==e||m.isNumber(e)||r.isDecimal(e)}function k(e){return!e||e.length==="####-##-##".length&&d(e).isValid()}function F(e,r){return h({},e,r)}function V(e){return function e(r,t){return Object.entries(r).reduce((function(n,o){var i,a,u=o[1],s=(a=o[0],m.isArray(r)?t+"["+a+"]":t?t+"."+a:a);return function(e){return(m.isArray(e)||m.isPlainObject(e))&&!!Object.keys(e).length}(u)?F(n,e(u,s)):F(n,((i={})[s]=u,i))}),{})}(e,"")}Object.defineProperty(exports,"flattenArray",{enumerable:!0,get:function(){return m.flatten}}),exports.CENT_DECIMAL=y,exports.DATE_FORMATS=b,exports.EMPTY_FIELD="--",exports.RE_ALPHA=v,exports.RE_SMALL_WORDS=g,exports.RE_WORDS=x,exports.canReplaceSymbols=O,exports.createDisabledContainer=function(e){var r=function(r){function t(){return r.apply(this,arguments)||this}return j(t,r),t.prototype.render=function(){var r=u(this.props.className,"disabled");return o.createElement(e,Object.assign({},this.props,{className:r,"data-for":"permission-required","data-tip":!0,"data-tip-disable":!1,onClick:null,onSelect:null}))},t}(n.Component);return r.displayName="DisabledContainer("+T(e)+")",t.__decorate([a.observer],r)},exports.createGuardedContainer=function(e){var r=e.isGuarded,u=e.enabledComponent,s=e.disabledComponent,p=function(e){function t(r){var t;return(t=e.call(this,r)||this).GuardedComponent=t.userHasPermission?u:s,t}var n,i;return j(t,e),t.prototype.render=function(){return o.createElement(this.GuardedComponent,Object.assign({},this.props))},n=t,(i=[{key:"userHasPermission",get:function(){return!r}}])&&function(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n.prototype,i),Object.defineProperty(n,"prototype",{writable:!1}),t}(n.Component);return p.displayName="GuardedContainer("+T(u)+")",t.__decorate([i.computed],p.prototype,"userHasPermission",null),t.__decorate([a.observer],p)},exports.dateToday=M,exports.flattenObject=V,exports.formatAddress=I,exports.formatAddressMultiline=function(e){return f(I(e).replace(", ","<br/>"))},exports.formatCommaSeparatedNumber=function(e){return S(e)?c(e).format("0,0"):"--"},exports.formatDate=A,exports.formatDateTime=function(e){return A(e,b.date_at_time)},exports.formatDelimitedList=function(e,r){return void 0===r&&(r=", "),e?P(e.join(r)):"--"},exports.formatDollars=function(e){return S(e)?c(e).format("$0,0"):"--"},exports.formatDuration=function(e){if(!N(e))return"--";var r=Object.entries(s.parse(e));return(r=r.filter((function(e){return e[1]>0}))).map((function(e){var r=e[0],t=e[1];return[1===t?r.slice(0,-1):r,t]})).map((function(e){return e[1]+" "+e[0]})).join(", ")},exports.formatEmployerIdNumber=function(e){return D(e,["##-#######"])},exports.formatFullName=function(e,r){return((e||"")+" "+(r||"")).trim()},exports.formatMoney=function(e){return S(e)?c(e).format("$0,0.00"):"--"},exports.formatMoneyInput=function(e){return S(e)?c(e).value():e},exports.formatNumberTemplates=D,exports.formatParagraphs=function(e){return N(e)?e.split(/\r?\n/).map((function(e,r){return o.createElement("p",{key:r},e)})):"--"},exports.formatPercentage=function(e,r){if(void 0===r&&(r=2),!S(e))return"--";var t="0."+m.times(r,(function(){return"0"})).join("")+"%";return c(e).format(t)},exports.formatPhoneNumber=function(e){return D(e,["###-####","(###) ###-####","+# (###) ###-####","+## (###) ###-####"])},exports.formatSocialSecurityNumber=function(e){return D(e,["####","###-##-####"])},exports.formatWebsite=function(e,r){return N(e)?o.createElement("a",{href:e,rel:"noopener noreferrer",target:"_blank"},r||e):"--"},exports.getDisplayName=T,exports.getInitials=function(e){if(!N(e))return"";var r=e.split(",")[0],t=m.startCase(r),n=t===m.upperCase(t);return t.match(x).map((function(e){var r=e===m.upperCase(e);return w(e)?"":r&&!n?e:e.charAt(0).toUpperCase()})).join("").substring(0,3)},exports.getNameOrDefault=function(e,r){var t=void 0===r?{}:r,n=t.field,o=void 0===n?"name":n,i=t.defaultValue,a=void 0===i?"--":i;if(e){if(m.has(e,"first_name"))return(m.result(e,"first_name","")+" "+m.result(e,"last_name","")).trim();if(m.has(e,o))return m.get(e,o)}return a},exports.getOrDefault=P,exports.getPercentDisplay=function(e){return U(e)?new r(e).times(y).toString():""},exports.getPercentValue=function(e){return U(e)?new r(e).div(y).toString():""},exports.getType=function(e){return e&&e.split(".")[1]||e},exports.hasStringContent=N,exports.hasStringOrNumberContent=S,exports.inferCentury=function(e){if(2!==e.length)return e;var r=""+M().substr(0,2)+e,t=""+d().subtract(100,"years").format("YYYY").substr(0,2)+e;return R(r+"-01-01")?t:r},exports.insertIf=function(e,r){return e?[r]:[]},exports.isFutureDate=R,exports.isValidDate=k,exports.isValidPastDate=function(e){return!e||k(e)&&d(e).isBefore(d())},exports.mapBooleanToText=function(e,r){var t=(void 0===r?{mapUndefinedToNo:!1}:r).mapUndefinedToNo;return m.isBoolean(e)?e?"Yes":"No":t&&void 0===e?"No":"--"},exports.parseAndPreserveNewlines=function(e){return N(e)?f(L(m.escape(e))):"--"},exports.pluralize=function(e,r,t){return 1===t?e:""+e+r},exports.preserveNewLines=L,exports.replaceSymbolsWithChars=_,exports.splitCommaList=function(e){return N(e)?-1===e.indexOf(",")?[e.trim()]:e.split(",").map((function(e){return e.trim()})).filter((function(e){return""!==e})):[]},exports.splitName=function(e){if(!N(e))return["",""];var r=e.trim().split(" ");return[r[0],r.slice(1).join(" ").trim()]},exports.stringToHTML=function(e){return f(e)},exports.stripNonAlpha=function(e){return N(e)?e.replace(v,""):""},exports.toKey=function(e){var r=m.sortBy(m.map(e,(function(e,r){return[r,e]}))),t=m.reject(r,(function(e){return null==e[1]}));return t.length<1?"":"?"+t.map((function(e){var r=e[1];return encodeURIComponent(e[0])+"="+encodeURIComponent(r)})).join("&")},exports.unflattenObject=function(e){return Object.entries(V(e)).reduce((function(e,r){return m.set(e,r[0],r[1])}),{})},exports.varToLabel=E;
//# sourceMappingURL=utils.cjs.production.min.js.map

@@ -12,3 +12,4 @@ import Decimal from 'decimal.js';

import memoize from 'fast-memoize';
import { isString, isNumber, has, result, get, times, isBoolean, escape, startCase, upperCase, sortBy, map, reject, mapValues } from 'lodash-es';
import { isString, isNumber, has, result, get, times, isBoolean, escape, startCase, upperCase, sortBy, map, reject, mapValues, isArray, isPlainObject, set } from 'lodash-es';
export { flatten as flattenArray } from 'lodash-es';
import moment from 'moment';

@@ -40,5 +41,26 @@

if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {

@@ -205,15 +227,11 @@ subClass.prototype = Object.create(superClass.prototype);

function getOrDefault(value) {
var isUndefined = value === undefined,
isNull = value === null,
isEmptyString = isString(value) && !hasStringContent(value);
if (isUndefined || isNull || isEmptyString) {
return EMPTY_FIELD;
if (hasStringContent(value)) {
return value.trim();
}
if (isString(value)) {
return value.trim();
if (isNumber(value)) {
return String(value);
}
return value;
return EMPTY_FIELD;
}

@@ -404,6 +422,6 @@ function formatSocialSecurityNumber(value) {

var MAX_CHARS = 3,
prefix = value.split(',')[0] || '',
prefix = value.split(',')[0],
formatted = startCase(prefix),
isValueAllCaps = formatted === upperCase(formatted),
wordArray = formatted.match(RE_WORDS) || [];
wordArray = formatted.match(RE_WORDS);
return wordArray.map(function (word) {

@@ -592,3 +610,54 @@ var isWordAllCaps = word === upperCase(word);

export { CENT_DECIMAL, DATE_FORMATS, EMPTY_FIELD, RE_ALPHA, RE_SMALL_WORDS, RE_WORDS, canReplaceSymbols, createDisabledContainer, createGuardedContainer, dateToday, formatAddress, formatAddressMultiline, formatCommaSeparatedNumber, formatDate, formatDateTime, formatDelimitedList, formatDollars, formatDuration, formatEmployerIdNumber, formatFullName, formatMoney, formatMoneyInput, formatNumberTemplates, formatParagraphs, formatPercentage, formatPhoneNumber, formatSocialSecurityNumber, formatWebsite, getDisplayName, getInitials, getNameOrDefault, getOrDefault, getPercentDisplay, getPercentValue, getType, hasStringContent, hasStringOrNumberContent, inferCentury, insertIf, isFutureDate, isValidDate, isValidPastDate, mapBooleanToText, parseAndPreserveNewlines, pluralize, preserveNewLines, replaceSymbolsWithChars, splitCommaList, splitName, stringToHTML, stripNonAlpha, toKey, varToLabel };
function mergeObjects(objectA, objectB) {
return _extends({}, objectA, objectB);
}
var _hasUnflattenedValues = function _hasUnflattenedValues(value) {
return (isArray(value) || isPlainObject(value)) && !!Object.keys(value).length;
};
function _flattenObject(input, parentKey) {
var _getFlatKey = function _getFlatKey(key) {
if (isArray(input)) {
return parentKey + "[" + key + "]";
}
if (parentKey) {
return parentKey + "." + key;
}
return key;
};
return Object.entries(input).reduce(function (output, _ref) {
var _mergeObjects;
var key = _ref[0],
value = _ref[1];
var flatKey = _getFlatKey(key);
if (_hasUnflattenedValues(value)) {
var flatValues = _flattenObject(value, flatKey);
return mergeObjects(output, flatValues);
}
return mergeObjects(output, (_mergeObjects = {}, _mergeObjects[flatKey] = value, _mergeObjects));
}, {});
}
function flattenObject(input) {
return _flattenObject(input, '');
}
function unflattenObject(object) {
return Object.entries(flattenObject(object)).reduce(function (objOut, _ref2) {
var key = _ref2[0],
value = _ref2[1];
return set(objOut, key, value);
}, {});
}
export { CENT_DECIMAL, DATE_FORMATS, EMPTY_FIELD, RE_ALPHA, RE_SMALL_WORDS, RE_WORDS, canReplaceSymbols, createDisabledContainer, createGuardedContainer, dateToday, flattenObject, formatAddress, formatAddressMultiline, formatCommaSeparatedNumber, formatDate, formatDateTime, formatDelimitedList, formatDollars, formatDuration, formatEmployerIdNumber, formatFullName, formatMoney, formatMoneyInput, formatNumberTemplates, formatParagraphs, formatPercentage, formatPhoneNumber, formatSocialSecurityNumber, formatWebsite, getDisplayName, getInitials, getNameOrDefault, getOrDefault, getPercentDisplay, getPercentValue, getType, hasStringContent, hasStringOrNumberContent, inferCentury, insertIf, isFutureDate, isValidDate, isValidPastDate, mapBooleanToText, parseAndPreserveNewlines, pluralize, preserveNewLines, replaceSymbolsWithChars, splitCommaList, splitName, stringToHTML, stripNonAlpha, toKey, unflattenObject, varToLabel };
//# sourceMappingURL=utils.esm.js.map
{
"name": "@mighty-justice/utils",
"version": "1.4.3",
"version": "1.5.0",
"description": "Standardization of small utilities across Mighty",

@@ -69,9 +69,9 @@ "main": "dist/index.js",

"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.9",
"@types/enzyme": "^3.10.11",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^27.0.1",
"@types/lodash": "^4.14.173",
"@types/jest": "^27.4.0",
"@types/lodash": "^4.14.178",
"@types/numeral": "^2.0.2",
"@types/react": "17.0.22",
"babel-jest": "^27.2.1",
"@types/react": "17.0.38",
"babel-jest": "^27.4.6",
"coveralls": "^3.1.1",

@@ -95,3 +95,3 @@ "enzyme": "^3.11.0",

"fast-memoize": "^2.5.2",
"html-react-parser": "1.3.0",
"html-react-parser": "1.4.5",
"iso8601-duration": "^1.1.7",

@@ -98,0 +98,0 @@ "moment": "^2.24.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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