Skip to content

Base64 encoding of date fails #46

Open
@andersnylund

Description

@andersnylund

The following functions caused me problems:

const toCursorHash = string => Buffer.from(string).toString('base64');
const fromCursorHash = string => (Buffer.from(string, 'base64').toString('utf-8');

Apparently the createdAt object passed to toCursorHash() was not of type string. I got the following error message:

TypeError [ERR_INVALID_ARG_TYPE]: The "value" argument must not be of type number. Received type number

Tested what type of the string is with javascripts typeof, and it revealed it to be of type object.

I fixed it with

const toCursorHash = string => Buffer.from(JSON.stringify(string)).toString('base64');
const fromCursorHash = string => JSON.parse(Buffer.from(string, 'base64').toString('utf-8'));

However, I'm curious of why this happened and why it appears to work for others as in the book.

Setup:

  • Windows 10 with WSL Ubuntu 18.04.1 LTS
  • Node v10.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions