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

@guardian/automat-contributions

Package Overview
Dependencies
Maintainers
44
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guardian/automat-contributions - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

2

dist/index.js

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

"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(r){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?t(Object(i),!0).forEach((function(t){e(r,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))}))}return r}Object.defineProperty(exports,"__esModule",{value:!0});var n,i,o=(n=new Date,1!==(i=n.getDay()||7)&&n.setHours(-24*(i-1)),Math.floor(n.getTime()/864e5)),s=new Set(["environment/climate-change","environment/environment","science/science","politics/politics","us-news/us-politics","australia-news/australian-politics","world/world","world/europe-news","world/russia","books/books","culture/culture","world/coronavirus-outbreak","world/race","inequality/inequality","technology/technology","business/business"]),c=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.forEach((function(e){var r;s.has(e)&&(t[e]=(null!==(r=t[e])&&void 0!==r?r:0)+1)})),t},u="gu.contributions.views",a=function(e){return e.get(u)||void 0},l="https://contributions.guardianapis.com/epic/compare-variant-decision",p="https://contributions.guardianapis.com/epic";exports.compareVariantDecision=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:l,r=JSON.stringify(e);fetch(t,{method:"post",headers:{"Content-Type":"application/json"},body:r}).catch((function(){}))},exports.getEpicMeta=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p,r=JSON.stringify(e);return fetch(t,{method:"post",headers:{"Content-Type":"application/json"},body:r})},exports.getViewLog=a,exports.getWeeklyArticleHistory=function(e){return e.get("gu.history.weeklyArticleCount")||void 0},exports.incrementWeeklyArticleCount=function(t,n,i){if(!function(t,n){var i=t.get("gu.history.articleCountsThisWeek");if(i&&i.week===o){var s=i.articles[n]||0;return t.set("gu.history.articleCountsThisWeek",{week:o,articles:r(r({},i.articles),{},e({},n,s+1))}),s>0}return t.set("gu.history.articleCountsThisWeek",{week:o,articles:e({},n,1)}),!1}(t,n)){var s=t.get("gu.history.weeklyArticleCount")||[],u=s[0];if(u&&u.week&&u.week===o)u.count+=1,u.tags=c(i,u.tags),t.set("gu.history.weeklyArticleCount",s);else{s.unshift({week:o,count:1,tags:c(i,{})});var a=o-365,l=s.filter((function(e){return e.week>=a}));t.set("gu.history.weeklyArticleCount",l)}}},exports.logView=function(e,t){var r=a(e)||[];r.push({date:(new Date).getTime(),testId:t}),e.set(u,r.slice(-50))};
"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(r){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?t(Object(i),!0).forEach((function(t){e(r,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))}))}return r}Object.defineProperty(exports,"__esModule",{value:!0});var n,i,o=(n=new Date,i=n.getDay()||7,Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()-(i-1))/864e5),s=new Set(["environment/climate-change","environment/environment","science/science","politics/politics","us-news/us-politics","australia-news/australian-politics","world/world","world/europe-news","world/russia","books/books","culture/culture","world/coronavirus-outbreak","world/race","inequality/inequality","technology/technology","business/business"]),c=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.forEach((function(e){var r;s.has(e)&&(t[e]=(null!==(r=t[e])&&void 0!==r?r:0)+1)})),t},u="gu.contributions.views",a=function(e){return e.get(u)||void 0},l="https://contributions.guardianapis.com/epic/compare-variant-decision",p="https://contributions.guardianapis.com/epic";exports.compareVariantDecision=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:l,r=JSON.stringify(e);fetch(t,{method:"post",headers:{"Content-Type":"application/json"},body:r}).catch((function(){}))},exports.getEpicMeta=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p,r=JSON.stringify(e);return fetch(t,{method:"post",headers:{"Content-Type":"application/json"},body:r})},exports.getViewLog=a,exports.getWeeklyArticleHistory=function(e){return e.get("gu.history.weeklyArticleCount")||void 0},exports.incrementWeeklyArticleCount=function(t,n,i){if(!function(t,n){var i=t.get("gu.history.articleCountsThisWeek");if(i&&i.week===o){var s=i.articles[n]||0;return t.set("gu.history.articleCountsThisWeek",{week:o,articles:r(r({},i.articles),{},e({},n,s+1))}),s>0}return t.set("gu.history.articleCountsThisWeek",{week:o,articles:e({},n,1)}),!1}(t,n)){var s=t.get("gu.history.weeklyArticleCount")||[],u=s[0];if(u&&u.week&&u.week===o)u.count+=1,u.tags=c(i,u.tags),t.set("gu.history.weeklyArticleCount",s);else{s.unshift({week:o,count:1,tags:c(i,{})});var a=o-365,l=s.filter((function(e){return e.week>=a}));t.set("gu.history.weeklyArticleCount",l)}}},exports.logView=function(e,t){var r=a(e)||[];r.push({date:(new Date).getTime(),testId:t}),e.set(u,r.slice(-50))};

@@ -6,19 +6,37 @@ import { getMondayFromDate } from './dates';

describe('getMondayFromDate', () => {
it('should return Monday midnight if today is Monday', () => {
const mondayMorning = new Date('2020-03-02T09:15:30');
const mondayMidnight = Math.floor(mondayMorning.getTime() / oneDay);
it('should return today if today is Monday', () => {
const mondayMorning = new Date('2021-09-20T09:15:30.000+00:00');
const monday = Math.floor(mondayMorning.getTime() / oneDay);
const mondayEvening = new Date('2020-03-02T19:25:00');
const mondayEvening = new Date('2021-09-20T19:25:00.000+00:00');
const got = getMondayFromDate(mondayEvening);
expect(got).toBe(mondayMidnight);
expect(got).toBe(monday);
});
it('should return Monday midnight today is some other day', () => {
const mondayMorning = new Date('2020-03-02T09:15:30');
const mondayMidnight = Math.floor(mondayMorning.getTime() / oneDay);
it('should return previous Monday if today is not Monday (UTC)', () => {
const mondayMorning = new Date('2020-03-02T09:15:30.000+00:00');
const monday = Math.floor(mondayMorning.getTime() / oneDay);
const fridayAfternoon = new Date('2020-03-06T16:35:00');
const fridayAfternoon = new Date('2020-03-06T16:35:00.000+00:00');
const got = getMondayFromDate(fridayAfternoon);
expect(got).toBe(mondayMidnight);
expect(got).toBe(monday);
});
it('should return previous Monday if today is not Monday (UTC+1)', () => {
const mondayMorning = new Date('2021-09-20T09:15:30.000+00:00');
const monday = Math.floor(mondayMorning.getTime() / oneDay);
const fridayAfternoon = new Date('2021-09-24T16:35:00.000+01:00')
const got = getMondayFromDate(fridayAfternoon);
expect(got).toBe(monday);
});
it('should return previous Monday if today is not Monday (UTC+1, close to midnight)', () => {
const mondayMorning = new Date('2021-09-20T00:15:30.000+00:00');
const monday = Math.floor(mondayMorning.getTime() / oneDay);
const fridayMorning = new Date('2021-09-24T00:35:00.000+01:00')
const got = getMondayFromDate(fridayMorning);
expect(got).toBe(monday);
});
});

@@ -5,8 +5,5 @@ // Helper function to handle history related Date objects.

export const getMondayFromDate = (date: Date): number => {
const day = date.getDay() || 7;
// Do not set date to Monday if it is already Monday
if (day !== 1) {
date.setHours(-24 * (day - 1));
}
return Math.floor(date.getTime() / 86400000);
const day = date.getDay() || 7; // Sunday is 0, so set it to 7
const time = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() - (day - 1))
return time / 86400000;
};
{
"name": "@guardian/automat-contributions",
"version": "0.4.1",
"version": "0.4.2",
"author": "Nicolas Long <nicolas.long@theguardian.com>",

@@ -5,0 +5,0 @@ "license": "MIT",

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