Skip to content

Commit

Permalink
Remove lodash dependency (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwillis committed May 13, 2024
1 parent ed4a7a0 commit e7bcd18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"lint": "eslint src test"
},
"dependencies": {
"archiver": "^5.3.0",
"lodash": "^4.17.4"
"archiver": "^5.3.0"
},
"devDependencies": {
"@apify/tsconfig": "^0.1.0",
Expand Down
9 changes: 4 additions & 5 deletions src/templates/cell.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isDate, isString, isNumber, isBoolean } from 'lodash';
import { sanitize, getNumberFormat, getDateFormat } from '../utils';

// 25569 = Days between 1970/01/01 and 1900/01/01 (min date in Windows Excel)
Expand All @@ -8,16 +7,16 @@ const OFFSET_DAYS = 25569;
const MILLISECONDS_IN_ONE_DAY = 86400000;

export default function (value, cell, shouldFormat) {
if (isDate(value)) {
if (value instanceof Date) {
const unixTimestamp = value.getTime();
const officeTimestamp = (unixTimestamp / MILLISECONDS_IN_ONE_DAY) + OFFSET_DAYS;
const maybeFormat = shouldFormat && getDateFormat();
return `<c r="${cell}" t="n"${maybeFormat ? ` s="${maybeFormat}"` : ''}><v>${officeTimestamp}</v></c>`;
} else if (isString(value)) {
} else if (typeof value === 'string') {
return `<c r="${cell}" t="inlineStr"><is><t>${sanitize(value)}</t></is></c>`;
} else if (isBoolean(value)) {
} else if (typeof value === 'boolean') {
return `<c r="${cell}" t="inlineStr"><is><t>${value}</t></is></c>`;
} else if (isNumber(value)) {
} else if (typeof value === 'number') {
const maybeFormat = shouldFormat && getNumberFormat(value);
return `<c r="${cell}" t="n"${maybeFormat ? ` s="${maybeFormat}"` : ''}><v>${value}</v></c>`;
} else if (value) {
Expand Down

0 comments on commit e7bcd18

Please sign in to comment.