Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE

Biowarfare posted:

Good old jQuery_jsonp1249805732097({...})

way to ruin my day by reminding me jsonp is a thing that existed :mad:

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Jsonp is great because you can return a response full of whatever code you want and it'll run it on the client. As nature intended.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
I’m having the dumbest time trying to understand react context and react hooks together. I’m simply trying to get a state variable to be shared between two components and have both components be able to modify the state. This is in NextJS btw. Anyways, I’m not sure if context is even the best way to do this, but I tried searching for some goods but it seems ike they’re all vague and assume you know what you’re doing (I don’t!). This is what I got so far off of using this guide as a base (https://www.netlify.com/blog/2020/12/01/using-react-context-for-state-management-in-next.js/):

code:
 import { useState, createContext, useContext } from "react";

const GeoContext = createContext();

export function GeoContextProvider ({children}) {
  const [geoviewport, setGeoViewport] = useState({
    width: "100vw",
    height: "100vh",
    latitude: 51.5074,
    longitude: -0.1278,
    zoom: 5,
  });

  return (
    <GeoContext.Provider value={[geoviewport, setGeoViewport]}>{children}</GeoContext.Provider>
  );
}

export function useGeoContext() {
  return useContext(GeoContextProvider);
}
Of which I call in my _app.js:

code:
 import "../styles/globals.css";
import Layout from "../components/layout";
import {GeoContextProvider} from '../lib/state';

function MyApp({ Component, pageProps }) {
  return (
    <GeoContextProvider>
      <Layout>
        <Component {...pageProps} />
      </Layout>
      </GeoContextProvider>
  );
}

export default MyApp;
But when I try to use it in a component, it doesn’t work. But I think that’s because I don’t really understand how to call it correctly:

code:
 import { useContext } from "react";
import ReactMapGL from "react-map-gl";
import Geocoder from "react-mapbox-gl-geocoder";
import { Container } from "@material-ui/core";
import { useGeoContext } from '../lib/state';

export default function Map() {

  let viewport, setViewport = useGeoContext();

  console.log(viewport)
  return (
    <ReactMapGL
      mapboxApiAccessToken={
        “KEYHERE”
      }
      mapStyle="mapbox://styles/mapbox/outdoors-v11"
      {...viewport}
      onViewportChange={(nextViewport) => setViewport(nextViewport)}
    ></ReactMapGL>
  );
}
Hoping one of you guys can point me in the right direction :v

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
…I figured it out. It was because I wasn’t restructuring correctly I guess. This is how I got it to work:


code:

export default function Map() {

  let viewport = useGeoContext();
  return (
    <ReactMapGL
      mapboxApiAccessToken={
        “KEY HERE
      }
      mapStyle="mapbox://styles/mapbox/outdoors-v11"
      {...viewport.geoviewport}
      onViewportChange={(nextViewport) => viewport.saveViewport(nextViewport)}
    ></ReactMapGL>
  );
}

Seems like there should be a way to destructor that viewport variable one more level though

necrotic
Aug 2, 2005
I owe my brother big time for this!
You want const [ viewport, setViewport ] = useGeoContext(); I think.

In your first post you were assigning setViewport only, viewport was not getting set.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Ill try that. I spent all day incredibly frustrated with nextjr and formik. I didn't expect there to be so many small gotchas with nextjr when trying to use npm modules.

I left the day feeling unaccomplished/a fraud so I think that's a good thing lmao. I could not for the life of me figure out how to pass a variable to a paramtere using Geocoding and Formik. Maybe if one of you goons. Know what I was doing wrong that's be great. Here's the stack overflow post I made

https://stackoverflow.com/questions/66375858/getting-value-from-component-with-formik-field

I dunno if it's my next install or what but I had a bunch of weird errors today trying to get small stuff to work I couldn't get mapbox to process a env variable even though it worked literally everywhere else in the app etc. Maybe I should just pay for google places sigh.

barkbell
Apr 14, 2006

woof
I'm not familar with formik and that geocoder package but check this out:

https://reactjs.org/docs/components-and-props.html#props-are-read-only

I imagine you are running into problems because onSelected is trying to modify the field prop. Try updating the state of the component instead, like in the example from that npm's package docs:
code:
    onSelected = (viewport, item) => {
        this.setState({viewport});
        console.log('Selected: ', item)
    }

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
That's a good idea i'm going to try that. Thanks :D

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
I'm randomly researching things regarding Javascript and React. What sort of patterns should I look at when I want to do something from traditional development, like loading/spawning forms or controls inside a container of a page (or app in case of Electron)? Say if I want an application frame with all sorts of navigation stuff, like a drawer and a breadcrumb bar, and then load the appropriate things into the content area. I'm not sure what I should look up for this. It's all happening in the render() function I guess?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Combat Pretzel posted:

I'm randomly researching things regarding Javascript and React. What sort of patterns should I look at when I want to do something from traditional development, like loading/spawning forms or controls inside a container of a page (or app in case of Electron)? Say if I want an application frame with all sorts of navigation stuff, like a drawer and a breadcrumb bar, and then load the appropriate things into the content area. I'm not sure what I should look up for this. It's all happening in the render() function I guess?

Have you tried react router? Doing a drawer or breadcrumb navigation is pretty straightforward if you google tutorials for it.

smackfu
Jun 7, 2004

It’s not like React is that complicated a mental model either. The render function has some inputs, some state, and an output. If you want a page that changes what it displays based on something, you just write some basic if-then code that does that.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
It's the lack of littering controls all over the application surface and accessing them by name that's not clicking yet.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
One thing I don't understand about React & State is whats the best way to set a global state? For example I have two components, a search box and a map. I'd like the search box upon submit to set the global state to a new variable and then the map reads it and updates it, but it doesn't work that way in theory so I have a weird thing where if you press search the map component won't update unless you refresh or what not, if that makes sense. It's something i've read that Vue handles fine but that's vue?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Empress Brosephine posted:

One thing I don't understand about React & State is whats the best way to set a global state? For example I have two components, a search box and a map. I'd like the search box upon submit to set the global state to a new variable and then the map reads it and updates it, but it doesn't work that way in theory so I have a weird thing where if you press search the map component won't update unless you refresh or what not, if that makes sense. It's something i've read that Vue handles fine but that's vue?

For a long time people used redux to handle global state in react, but that's probably overkill with recent versions. I would look into the context api (e.g. https://reactjs.org/docs/context.html).

Chas McGill
Oct 29, 2010

loves Fat Philippe

Empress Brosephine posted:

One thing I don't understand about React & State is whats the best way to set a global state? For example I have two components, a search box and a map. I'd like the search box upon submit to set the global state to a new variable and then the map reads it and updates it, but it doesn't work that way in theory so I have a weird thing where if you press search the map component won't update unless you refresh or what not, if that makes sense. It's something i've read that Vue handles fine but that's vue?
If it's just those two components, I'd just put them in something like <MapView />, which would hold the state, then pass down a setter to your <Search /> component and when that is called, the updated state can be passed to your <Map /> component. No need for context or redux if you're only going one level deep.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Thank you both those both are good ideas.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I have a little server.

code:
//index.js
const http = require('http');
const app = require('./app.js');

const server = http.createServer(app);

server.listen(4000, function () {
  console.log('Server running on port 4000');
});
And a little app.

code:
// app.js
function app (req, res) {
  // do some req res
}

module.exports = app;
Now I want to write unit tests for `app.js`. I shouldn't need to run a server to test the functionality, but I'm not coming up with a lot regarding how to make those `req` and `res` objects. I know I can create them:

code:
const http = require('http');

const req = new http.ClientRequest();
const res = new http.ServerResponse();
But there doesn't seem to be documentation about what parameters either of these take, so I don't know how to for example set the path or method being invoked in `req`. Are there existing libraries for this sort of thing or has the entire world abandoned anything to do with nodejs and just use express.

Impotence
Nov 8, 2010
Lipstick Apathy
just use express, no one uses raw http for a reason

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Well express doesn't do what I'm trying to do either. You gotta spin up a server and probe it with supertest, or you have to just unit test your route definition files. No way to inject a request into the app for some reason. That's right I'm pointing it all out. This blimp is coming down! Lazy devs all over.

Doom Mathematic
Sep 2, 2008
So I am reasonably sure that you aren't supposed to be manually constructing new http.ClientRequests and http.ServerResponses yourself. If you're averse to spinning up a HTTP server and using real HTTP requests and responses, you need mock requests and responses.

However, I would be inclined to figure out a way to separate out the logic of the application from the HTTP layer. I'd much rather test the application by driving it with regular function calls.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
All joking aside I have mocked server requests and responses.

https://github.com/Kequc/kequserver/tree/main/src/inject

Which may not be the right solution. I probably could have given up after I figured out that node really didn't want me messing with http objects, and that I'm really not supposed to be doing what I've done.

This doesn't seem like an optimal solution because I had to inspect the objects like crazy and the variables that were coming up don't even match the documentation. Who knows how long my mocks will remain valid. For example the `headers` parameter doesn't exist when you inspect the `ClientRequest` instance. Nor does any of the `setHeader`, `getHeader` etc, but it's in the docs and does work if you use it. On the `ServerResponse` object `_headers` exists and all of the extra methods that work on `ClientRequest` but `headers` also works even though it isn't there.

So who knows.

Maybe the correct solution in node is just make a server and send requests to yourself. Maybe that isn't even a lot of processing.

Nolgthorn fucked around with this message at 03:16 on Mar 2, 2021

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Sorry to interrupt with yet another question but I'm not really clicking with React and/or NextJS or i'm trying to make it do things that it can't do...so is this even possible? :

I have a form that lets you select a city. Upon selecting a city and hitting the submit button, the app would take the value of the form fields and passes it to a database to filter/query. The database returns the data and then the app uses that new data as it needs.

I've been trying for the past three days to figure this out but I can't get it to work the way I think it should in Nextjs or React. The closest i've gotten so far is when I try to access the db within my form handleSubmit function, I get what might be the most vague error of all time:

Unhandled Runtime Error

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

But I don't use classes :iiam:

So i'm just trying to wonder if this is even possible. I know how to do this with something like express rather easily, but it's not dynamic and requires a re-render. Think i've about ripped my hair out trying to figure this and retrieving and setting state between two components over the past few days.

Empress Brosephine fucked around with this message at 06:11 on Mar 2, 2021

Roadie
Jun 30, 2013

Empress Brosephine posted:

Sorry to interrupt with yet another question but I'm not really clicking with React and/or NextJS or i'm trying to make it do things that it can't do...so is this even possible? :

I have a form that lets you select a city. Upon selecting a city and hitting the submit button, the app would take the value of the form fields and passes it to a database to filter/query. The database returns the data and then the app uses that new data as it needs.

I've been trying for the past three days to figure this out but I can't get it to work the way I think it should in Nextjs or React. The closest i've gotten so far is when I try to access the db within my form handleSubmit function, I get what might be the most vague error of all time:

Unhandled Runtime Error

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

But I don't use classes :iiam:

So i'm just trying to wonder if this is even possible. I know how to do this with something like express rather easily, but it's not dynamic and requires a re-render. Think i've about ripped my hair out trying to figure this and retrieving and setting state between two components over the past few days.

What does "access the db" mean in this context? You're really not giving enough information here.

Also, that error is pretty straightforward: you're trying to JSON.parse something that isn't JSON.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Empress Brosephine posted:

So i'm just trying to wonder if this is even possible. I know how to do this with something like express rather easily, but it's not dynamic and requires a re-render. Think i've about ripped my hair out trying to figure this and retrieving and setting state between two components over the past few days.

It's totally possible.

Maybe post code or put project on git etc?

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Yeah if you all don't mind looking at it. It's nothing complex since I've been trying to figure this out lol. Thanks for taking a moment to look.

https://github.com/disneyquesting/campgroundSearchFinal

In pseudo code terms "accessing the db" means having the handle Submit function send the query to the Api functions to get data, so with the above code ( https://github.com/disneyquesting/campgroundSearchFinal/blob/main/lib/api.js ) I'm trying to call getCamogroundsByCity from this https://github.com/disneyquesting/campgroundSearchFinal/blob/main/components/newsearch.js



These are the main files I've been working on; there's alot of garbage in that project since I've been determined on trying to get this to work

https://github.com/disneyquesting/campgroundSearchFinal/blob/main/components/searchbox.js

This one you can see the commented out code that kinda works, but I can't figure out the right way to get the campgroundsbycity to call

https://github.com/disneyquesting/campgroundSearchFinal/blob/main/components/newsearch.js

That was me just trying to get something to work.



https://github.com/disneyquesting/campgroundSearchFinal/blob/main/components/map.js

That's the map component

https://github.com/disneyquesting/campgroundSearchFinal/blob/main/pages/camps.js

https://github.com/disneyquesting/campgroundSearchFinal/blob/main/pages/index.js

The two main pages so far.


Thanks for looking i appreciate it!!

TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE

Nolgthorn posted:

I have a little server.

code:
//index.js
const http = require('http');
const app = require('./app.js');

const server = http.createServer(app);

server.listen(4000, function () {
  console.log('Server running on port 4000');
});
And a little app.

code:
// app.js
function app (req, res) {
  // do some req res
}

module.exports = app;
Now I want to write unit tests for `app.js`. I shouldn't need to run a server to test the functionality, but I'm not coming up with a lot regarding how to make those `req` and `res` objects. I know I can create them:

code:
const http = require('http');

const req = new http.ClientRequest();
const res = new http.ServerResponse();
But there doesn't seem to be documentation about what parameters either of these take, so I don't know how to for example set the path or method being invoked in `req`. Are there existing libraries for this sort of thing or has the entire world abandoned anything to do with nodejs and just use express.

If you want to test a request handler then you should probably use supertest or something similar, which does run a server for you and actually does send local HTTP requests. The HTTP request/response handling is an integral part of the unit you're testing in this case, so it would be a mistake to try to mock the request and response IMO. Some purists may argue that this makes it not a unit test anymore but rather an integration test but I think that's pointless nitpicking.

On the other hand if you want to unit test a bit of functionality that is used by a request handler then you should extract that bit of functionality into its own function or something (its own unit, as it were) such that it can be unit tested.

TheFluff fucked around with this message at 11:14 on Mar 2, 2021

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
It seems by going the super minimalist route I've shot myself in the foot with regard to unit testing, as node doesn't make these objects available outside of an actual networking request. You're right probably, my only options are to completely abstract the native objects out of the picture, or use supertest.

I think I got enamored with fastify's solution which does something similar. But after reading the code they're using a giant library that is so large that it has to be conditionally loaded to make the integration possible. That seems less efficient than just creating http requests.

It was an interesting deep dive into node networking anyway.

Nolgthorn fucked around with this message at 12:55 on Mar 2, 2021

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer
Our approach is: end to end/integration tests against api endpoints, and untested thin handler functions that take the relevant data off requests and pass them to the actual logic functions which are unit tested, and return data which are then put on the responses again by the thin function.

Basically mocking requests is making your life more difficult in order to test mostly other people's code (express or whatever)

Osmosisch fucked around with this message at 13:14 on Mar 2, 2021

Infected Mushroom
Nov 4, 2009

Nolgthorn posted:

It seems by going the super minimalist route I've shot myself in the foot with regard to unit testing, as node doesn't make these objects available outside of an actual networking request. You're right probably, my only options are to completely abstract the native objects out of the picture, or use supertest.

I think I got enamored with fastify's solution which does something similar. But after reading the code they're using a giant library that is so large that it has to be conditionally loaded to make the integration possible. That seems less efficient than just creating http requests.

It was an interesting deep dive into node networking anyway.

You can manually create the request & response objects — make a request with the http.request function (which is just a wrapper around the ClientRequest constructor) and a ServerResponse only needs a request

Like everyone else said, it's probably a bad idea as they're not really intended to be used like that

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I thought that was for performing actual http requests. So by creating a req object in this way my tests are going to attempt to communicate with whatever URL I put in there. And because I'm then channeling that req into a workflow that will do God knows what with it, and because it is trying to communicate via http simultaneously in the background, won't it likely throw an error?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Empress Brosephine posted:

This one you can see the commented out code that kinda works, but I can't figure out the right way to get the campgroundsbycity to call

I would check if your api call is failing using something like fiddler/postman, and what the api is actually returning. Sometimes if a data service is failing on a web server, instead of returning json, it'll return something like "<html>Unhandled exception...." because a generic error handler is invoked because something bad happened like authorization didn't work (e.g because service protected using token auth and token not provided), or service isn't running, etc (even though you asked for JSON, it's entirely possible error pages don't respect that). The client tries to deserialize that returned generic error page as json, and "<" as the first character in the json string causes parser to spit nails because that's Not JSON.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS

Bruegels Fuckbooks posted:

I would check if your api call is failing using something like fiddler/postman, and what the api is actually returning. Sometimes if a data service is failing on a web server, instead of returning json, it'll return something like "<html>Unhandled exception...." because a generic error handler is invoked because something bad happened like authorization didn't work (e.g because service protected using token auth and token not provided), or service isn't running, etc (even though you asked for JSON, it's entirely possible error pages don't respect that). The client tries to deserialize that returned generic error page as json, and "<" as the first character in the json string causes parser to spit nails because that's Not JSON.

I feel stupid for not even thinking of trying that. I'll try that and report back. Thanks for the help!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Looks like supertest starts a server on port 0 which I didn't know you can do. That's nice at least.

https://github.com/visionmedia/supertest/blob/master/lib/test.js#L56

Then I suppose I just make requests to my app in a wrapper running at that location, that'll be my solution I think after I get something to eat.

TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE

Nolgthorn posted:

Looks like supertest starts a server on port 0 which I didn't know you can do. That's nice at least.

https://github.com/visionmedia/supertest/blob/master/lib/test.js#L56

Then I suppose I just make requests to my app in a wrapper running at that location, that'll be my solution I think after I get something to eat.

Passing 0 as the port number to server.listen() just means "listen on a random unused port". See the node docs for net.server. I'm not sure what you're trying to do, here - are you reimplementing supertest functionality yourself?

Good Sphere
Jun 16, 2018

Pako JS: I have a 400-character string I'd like to compress down to URL-safe characters. I turn the string into an array by using split, since Pako seems to require an array and not a plain string. The length of the compressed array is 137, which I consider a good result, but the compressed object is made up of a list of 3-digit numbers, which is undesirable. I want the result to be a string single characters, not 3-digit numbers.

Is there enough single characters to represent each number that are URL-safe?

Is there an easy way to apply this to the compression, and then uncompress it to its original 400-character string?

code:
var stringToCompress = "nnnnnnnnnnnnnnnnnnnnnnnnunnnnnnnnnnnnuuunnnuxunnnnnnnnnnuxddnnnuxduuuuuunnnnuxddnnnuxddddddunnnnuxddnuuuxdddddduuuuuuxddnnnuxdIoodduccuduxddnnnuxdIuodduCCuduxddnnnuxdIIodduccuduxddnnnuxdddddduCCuduxddnnnuxdddddduccuduxddnnnuxdddddduCCuduxddnnnuxdIoodduccuduxddnuuuxdIuodduCCuduxddnnnuxdIIodduccuxuxddnnnuxdddddduuuuuuxddnnnuxxxxxxxunnnnuxxxnnnnuuuuuuuunnnnnuuunnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"

var strArr = JSON.stringify(stringToCompress.split(''));
var result = pako.deflate(JSON.stringify(strArr));
console.log("result = " + result)
console.log("result length = " + result.length)
console.log("stringToCompress length = " + stringToCompress.length)
var inflated = JSON.parse(pako.inflate(result, { to: 'string' }));
console.log("inflated = " + inflated)

Impotence
Nov 8, 2010
Lipstick Apathy
It's not actually a list of 3 digit numbers. You have a Uint8array as output.

You can probably use something like https://github.com/WebReflection/uint8-to-base64

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

TheFluff posted:

Passing 0 as the port number to server.listen() just means "listen on a random unused port". See the node docs for net.server. I'm not sure what you're trying to do, here - are you reimplementing supertest functionality yourself?

I'm building a little server requestListener lib for node.

https://github.com/Kequc/kequserver

I'm unsatisfied with supertest because it doesn't allow me to test streaming, and it is heavy handed for my minimalist little tiny lib. I'm interested in just working on it here and there learning about multipart requests and so on, implementing those details. Right now I'm concerned about being able to test.

Part of me thinks it's outside the scope of the lib, because someone could use the lib and just install supertest. But it's all a learning experience.

Good Sphere
Jun 16, 2018

Biowarfare posted:

It's not actually a list of 3 digit numbers. You have a Uint8array as output.

You can probably use something like https://github.com/WebReflection/uint8-to-base64

Thank you! The Uint8array part was really helpful. I'm using this code: https://stackoverflow.com/a/36046727/586006

Edit: Ugh. It's not working for me since it uses spaces and forward slashes.

Good Sphere fucked around with this message at 21:41 on Mar 2, 2021

Impotence
Nov 8, 2010
Lipstick Apathy

Good Sphere posted:

Thank you! The Uint8array part was really helpful. I'm using this code: https://stackoverflow.com/a/36046727/586006

Edit: Ugh. It's not working for me since it uses spaces and forward slashes.

to b64 .replace(/\//g, '_').replace(/\+/g, '-')))
from b64 .replace(/_/g, '/').replace(/-/g, '+')


Adbot
ADBOT LOVES YOU

Good Sphere
Jun 16, 2018

Biowarfare posted:

to b64 .replace(/\//g, '_').replace(/\+/g, '-')))
from b64 .replace(/_/g, '/').replace(/-/g, '+')

Exactly what I needed. Thank you.

Now to see how this compression holds up to my own. I'm suspicious as a more noisy image only compressed down to 396/400.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply