Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
refactor: rename print to toString
Browse files Browse the repository at this point in the history
  • Loading branch information
lachrist committed Sep 8, 2022
1 parent f6fdb60 commit 85aa14b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions components/frontend/default/convert.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { apply } = Reflect;
const _String = String;
const _undefined = undefined;
const {
prototype: { toString },
prototype: { toString: toStringBuiltin },
} = Object;

const { round } = Math;
Expand All @@ -19,7 +19,7 @@ export const toInteger = (any) => {
}
};

export const print = (any) => {
export const toString = (any) => {
if (typeof any === "string") {
return any;
} else if (
Expand All @@ -32,6 +32,6 @@ export const print = (any) => {
) {
return _String(any);
} else {
return apply(toString, any, []);
return apply(toStringBuiltin, any, []);
}
};
8 changes: 4 additions & 4 deletions components/frontend/default/convert.test.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { assertEqual } from "../../__fixture__.mjs";

import { print, toInteger } from "./convert.mjs";
import { toString, toInteger } from "./convert.mjs";

assertEqual(print("foo"), "foo");
assertEqual(toString("foo"), "foo");

assertEqual(print(123), "123");
assertEqual(toString(123), "123");

assertEqual(
print(function f() {}),
toString(function f() {}),
"[object Function]",
);

Expand Down
2 changes: 1 addition & 1 deletion components/frontend/default/payload.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (dependencies) => {

const hasStringKey = ([key]) => typeof key === "string";

const printValue = ([key, value]) => [key, print(value)];
const printValue = ([key, value]) => [key, toString(value)];

const formatHeaders = (headers) =>
fromEntries(toEntries(headers).filter(hasStringKey).map(printValue));
Expand Down

0 comments on commit 85aa14b

Please sign in to comment.