Giter Club home page Giter Club logo

Comments (8)

Aslemammad avatar Aslemammad commented on June 12, 2024 1

Sure why not?

from .github.

Aslemammad avatar Aslemammad commented on June 12, 2024 1

Thank you so much, I'll transfer it here and we can continue working on it.

from .github.

Aslemammad avatar Aslemammad commented on June 12, 2024 1

@jcbhmr I moved the repo to tinylibs, now let's discuss changing names to tinylet and stuff there, please create a discussion there or let's discuss in my discord (preferably) Aslemammad#6670

from .github.

Aslemammad avatar Aslemammad commented on June 12, 2024

I believe this is something possible, do you use it in any of your projects?

from .github.

jcbhmr avatar jcbhmr commented on June 12, 2024

Here's an example of something similar redlet() which I used to synchronously wait for user input for a prompt() polyfill:

function prompt(message: string = "", default_: string = ""): string | null {
  message = "" + message;
  default_ = "" + default_;

  // The prompt(message, default) method steps are:

  // 1. If we cannot show simple dialogs for this, then return null.
  if (cannotShowSimpleDialogs()) {
    return null;
  }

  // 2. Set message to the result of normalizing newlines given message.
  message = normalizeNewlines(message);

  // 5. Show message to the user, treating U+000A LF as a line break, and ask
  //    the user to either respond with a string value or abort. The response
  //    must be defaulted to the value given by default.
  // 7. Pause while waiting for the user's response.
  // 8. Let result be null if the user aborts, or otherwise the string that the
  //    user responded with.
  const result = redlet(
    async (message: string, default_: string): Promise<string> => {
      const { createInterface } = await import("node:readline/promises");
      const { pEvent } = await import("p-event");

      const rl = createInterface({
        input: process.stdin,
        output: process.stderr,
      });

      return await Promise.any([
        rl
          .question(
            (message ? message + "\n" : message) +
              (default_ ? `[${default_}] > ` : "> ")
          )
          .then((a) => (a.trim() ? a : default_)),
        pEvent(rl, "close").then(() => (console.log(), null)),
      ]);
    }
  )(message, default_);

  // 10. Return result.
  return result;
}

Here's another one for a FileReaderSync polyfill/ponyfill for Node.js:

const readAsArrayBufferSync = yellowlet((blob: Blob) => blob.arrayBuffer())
const readAsTextSync = yellowlet((blob: Blob) => blob.text())

export default class FileReaderSync {
  #asciiDecoder: TextDecoder | null | undefined;

  readAsArrayBuffer(blob: Blob): ArrayBuffer {
    return readAsArrayBufferSync (blob);
  }

  readAsBinaryString(blob: Blob): string {
    const buffer = this.readAsArrayBuffer();
    this.#asciiDecoder ??= new TextDecoder("ascii");
    return this.#asciiDecoder.decode(buffer);
  }

  readAsText(blob: Blob): string {
    return readAsTextSync(blob);
  }

  readAsDataURL(blob: Blob): string {
    const binaryString = this.readAsBinaryString();
    const base64 = btoa(binaryString);
    return `data:${blob.type};base64,${base64}`;
  }
}

These use-cases are a bit niche to say the least. 🤷‍♀️

from .github.

Aslemammad avatar Aslemammad commented on June 12, 2024

I think it'd be an amazing idea, thank you so much! I'll work on it soon.

from .github.

jcbhmr avatar jcbhmr commented on June 12, 2024

I've done some preliminary codey-codes in https://github.com/jcbhmr/tinythreadlet, and I would like to transfer it to the @tinylibs namespace. Would that be OK with you?

from .github.

jcbhmr avatar jcbhmr commented on June 12, 2024

I am "unable to create repositories in the tinylibs organization" but I was able to just transfer it to you, @Aslemammad. 👍

from .github.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.