YoptaScript Documentation

repository·master·Indexed 24 days ago

https://github.com/samgozman/yoptascript

YoptaScript is a programming language that transpiles into clean JavaScript using a specific slang dialect. Version 2.0.6 provides a runtime for browser execution, an npm package for Node.js projects, and a compile function to transform text between YoptaScript (ys) and JavaScript (js). It features a customizable dictionary mapping standard JS/TS tokens to slang equivalents and supports various local dialects for boolean values and operators.

Tokens
1.6K
Snippets
5
Records
13
Agent score
81%

What's inside YoptaScript

  1. Dialect and Character Support in YoptaScript

    master

    YoptaScript supports various local dialects for boolean values and operators. Additionally, it provides flexible character handling for Cyrillic text:

    • Boolean True: трулио, чётко, четко, чотко
    • Boolean False: нетрулио, пиздишь, нечётко, нечетко, нечотко
    • Equality Operator (==): эквалио, ровно, однахуйня, типа

    Character Rules:

    • You can replace the letter ё with е in any method or property name.
    • If a word contains ё in the middle, you can also replace it with о and Yopta will still recognize it.
  2. Contribution workflow and branching rules

    master

    When contributing to YoptaScript, follow these workflow rules:

    1. Branching: Do not merge pull requests directly into the master branch. Use dedicated developer branches for your work.
    2. Content Policy: The dictionary must remain free of nationalist, political, and religious jargon.
  3. Use YoptaScript in the Browser

    master

    To run YoptaScript in a web browser, you need to include the yopta.js runtime and define your code within a script tag marked with language="YoptaScript".

    <body
        <!-- 1. Define your YoptaScript code -->
        <script language="YoptaScript">
            ксива.малява(" Оно работает ") нах
        </script>
    
        <!-- 2. Include the YoptaScript runtime (via local file or CDN) -->
        <script src="https://cdn.jsdelivr.net/npm/yopta/dist/yopta.min.js"></script>
    </body>
  4. Set up the YoptaScript development environment

    master

    To contribute to YoptaScript, fork the repository and set up your local environment using Node.js and npm.

    1. Install Visual Studio Code (recommended).
    2. Install Node.js and npm.
    3. Clone your fork and run npm i in the project root.

    Use the following commands to manage your development workflow:

    • npm run test-local: Builds the project and runs tests.
    • npm run dev: Builds the project and starts a local server at http://localhost:1488/demo/ to preview code examples.
    npm i
    npm run test-local
    npm run dev
  5. Extend the YoptaScript dictionary

    master

    You can contribute to the linguistic aspect of YoptaScript by adding new values to the dictionary.

    • File location: src/dictionary/dictionary.ts
    • Requirement: Ensure you check for duplicates before adding new entries to avoid redundant implementations.
    • Restriction: Do not add nationalist, political, or religious jargon to the dictionary.
  6. Configure md-prettify for YoptaScript

    master

    You can use the md-prettify VS Code extension to automatically transform standard code into YoptaScript in your markdown files. To enable this, add the following configuration to your VS Code settings:

    "mdPrettify.predefinedConfig": "typescript-to-yoptascript"
  7. Automatic YoptaScript execution in the browser

    master

    When running in a browser environment, YoptaScript can be automatically detected and compiled by the library. The library searches for and processes script elements that match either of the following criteria:

    1. Elements with the attribute language="YoptaScript".
    2. Elements with the type type="text/x-yoptascript".

    For elements with a src attribute, the library will fetch the content via a GET request before compiling. Once compiled, the original script element is removed and replaced by a new <script> element containing the compiled JavaScript appended to the document.body.

  8. Modify the YoptaScript language dictionary

    master

    The dictionary constant in src/dictionary/dictionary.ts defines the mapping between standard JavaScript/TypeScript tokens and their YoptaScript equivalents. To extend the language vocabulary or change existing mappings, you must add or edit entries in this array.

    Each entry is a tuple in the format ['original_token', 'yoptascript_equivalent']. The array supports multiple mappings for the same token to allow for different dialect variations or synonyms.

    export const dictionary = [
        ['break', 'харэ'],
        ['case', 'лещ'],
        // ...
    ];
  9. Compile YoptaScript using compile()

    master

    The compile function transforms text between YoptaScript (ys) and JavaScript (js). It handles the translation of keywords based on a dictionary and manages the preservation of JSX content, string literals, and comments during the transformation process.

    Parameters

    • text (string): The source text to be transformed.
    • lang (string, default: 'ys'): The target language. Use 'ys' to compile YoptaScript to JavaScript, or 'js' to compile JavaScript back to YoptaScript.

    Returns

    • string: The transformed text in the requested language.
  10. Access the compile function via the global 'yopta' object

    master

    When running in an environment where the YoptaScript polyfill is applied, the compile function is automatically attached to the global scope under the yopta property.

    This allows you to call yopta.compile(text, lang) directly in browser or Node.js environments without explicit imports, provided the library has been initialized.

  11. Compile YoptaScript using the yopta function

    master

    The yopta function (exported from the package entrypoint) is used to compile YoptaScript code into JavaScript. It is an alias for the core compile function.

    To use it in a module environment, import yopta from the package.