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

@govuk-frederic/utils

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@govuk-frederic/utils - npm Package Compare versions

Comparing version 0.0.4 to 0.0.6

es/test.js

46

es/tableUtils/index.js

@@ -39,3 +39,9 @@ export var objectHasValueForKeys = function objectHasValueForKeys(item, keys) {

};
export var rowsFromArray = function rowsFromArray(array, fields, skipEmptyRows) {
export var rowsFromArray = function rowsFromArray(array, fields, skipEmptyRows, defaultTransform) {
if (defaultTransform === void 0) {
defaultTransform = function defaultTransform(value) {
return value || '-';
};
}
var keys = keysFromFields(fields);

@@ -47,6 +53,4 @@ return array.reduce(function (rows, item) {

_ref2$transform = _ref2.transform,
transform = _ref2$transform === void 0 ? function (result) {
return result || '-';
} : _ref2$transform;
return transform(item[key], item);
transform = _ref2$transform === void 0 ? defaultTransform : _ref2$transform;
return transform(item[key]);
}));

@@ -62,2 +66,8 @@ }

export var rowsFromObject = function rowsFromObject(object, fields, skipEmptyValues, defaultTransform) {
if (defaultTransform === void 0) {
defaultTransform = function defaultTransform(value) {
return value;
};
}
return fields.reduce(function (table, _ref3) {

@@ -67,26 +77,10 @@ var key = _ref3.key,

names = _ref3.names,
transform = _ref3.transform;
var result; // If there is a name attribute in the fields object use it, otherwise fallback to the key
_ref3$transform = _ref3.transform,
transform = _ref3$transform === void 0 ? defaultTransform : _ref3$transform;
// If there is a name attribute in the fields object use it, otherwise fallback to the key
var nameAttribute = names ? names : key; // Run any passed transforms and normalise undefined values to an empty string
var nameAttribute = names ? names : key; // Do we have a specific transform to run?
if (transform) {
result = transform(object[key], object); // if not, do we have a default transform to run?
} else if (defaultTransform) {
result = defaultTransform(object[key], object);
} else {
result = object[key];
} // Is the value undefined?
// This can happen if there;
// is no property in the object for provided key AND
// there is no value for a found property in the object
if (result === undefined) {
// If it is, normalise it to an empty string so we can decide if we want skip rendering or not
result = '';
} // Empty values are empty strings (normalised above)
var result = transform(object[key], object) || ''; // Empty values are empty strings (normalised above)
// We never render null
if (result !== null && !(skipEmptyValues && result === '')) {

@@ -93,0 +87,0 @@ table.rows.push([heading, result]);

@@ -55,3 +55,9 @@ "use strict";

var rowsFromArray = function rowsFromArray(array, fields, skipEmptyRows) {
var rowsFromArray = function rowsFromArray(array, fields, skipEmptyRows, defaultTransform) {
if (defaultTransform === void 0) {
defaultTransform = function defaultTransform(value) {
return value || '-';
};
}
var keys = keysFromFields(fields);

@@ -63,6 +69,4 @@ return array.reduce(function (rows, item) {

_ref2$transform = _ref2.transform,
transform = _ref2$transform === void 0 ? function (result) {
return result || '-';
} : _ref2$transform;
return transform(item[key], item);
transform = _ref2$transform === void 0 ? defaultTransform : _ref2$transform;
return transform(item[key]);
}));

@@ -81,2 +85,8 @@ }

var rowsFromObject = function rowsFromObject(object, fields, skipEmptyValues, defaultTransform) {
if (defaultTransform === void 0) {
defaultTransform = function defaultTransform(value) {
return value;
};
}
return fields.reduce(function (table, _ref3) {

@@ -86,26 +96,10 @@ var key = _ref3.key,

names = _ref3.names,
transform = _ref3.transform;
var result; // If there is a name attribute in the fields object use it, otherwise fallback to the key
_ref3$transform = _ref3.transform,
transform = _ref3$transform === void 0 ? defaultTransform : _ref3$transform;
// If there is a name attribute in the fields object use it, otherwise fallback to the key
var nameAttribute = names ? names : key; // Run any passed transforms and normalise undefined values to an empty string
var nameAttribute = names ? names : key; // Do we have a specific transform to run?
if (transform) {
result = transform(object[key], object); // if not, do we have a default transform to run?
} else if (defaultTransform) {
result = defaultTransform(object[key], object);
} else {
result = object[key];
} // Is the value undefined?
// This can happen if there;
// is no property in the object for provided key AND
// there is no value for a found property in the object
if (result === undefined) {
// If it is, normalise it to an empty string so we can decide if we want skip rendering or not
result = '';
} // Empty values are empty strings (normalised above)
var result = transform(object[key], object) || ''; // Empty values are empty strings (normalised above)
// We never render null
if (result !== null && !(skipEmptyValues && result === '')) {

@@ -112,0 +106,0 @@ table.rows.push([heading, result]);

{
"name": "@govuk-frederic/utils",
"version": "0.0.4",
"version": "0.0.6",
"scripts": {

@@ -5,0 +5,0 @@ "build": "npm run build:lib && npm run build:es",

@@ -15,3 +15,3 @@ export const objectHasValueForKeys = (item = {}, keys = []) => Object.entries(item).reduce(

export const rowsFromArray = (array, fields, skipEmptyRows) => {
export const rowsFromArray = (array, fields, skipEmptyRows, defaultTransform = value => (value || '-')) => {
const keys = keysFromFields(fields);

@@ -22,3 +22,3 @@

rows.push(
fields.map(({ key, transform = result => (result || '-')}) => transform(item[key], item)),
fields.map(({ key, transform = defaultTransform}) => transform(item[key])),
);

@@ -48,3 +48,3 @@ }

}
return table;

@@ -51,0 +51,0 @@ },

@@ -8,3 +8,3 @@ import * as exports from '.';

{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two', transform: () => 'two' },
{ key: 'two', heading: 'Two', transform: value => (value || 'two') },
{ key: 'three', heading: 'Three' },

@@ -18,6 +18,6 @@ ];

let rows = rowsFromArray(array, fields, false);
expect(rows).toEqual([['-', 'two', '-'], ['test', 'two', '-']]);
expect(rows).toEqual([['-', 'two', '-'], ['test', 'test', '-']]);
rows = rowsFromArray(array, fields, true);
expect(rows).toEqual([['test', 'two', '-']]);
expect(rows).toEqual([['test', 'test', '-']]);
});

@@ -24,0 +24,0 @@ });

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