npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gelight/sml-client

v0.2.2

Published

SML - The Simple Markup Language for Browsers

Downloads

27

Readme

SML Client

The Simple Markup Language for clients

You also can get help in the german version inside the @gelight/sml package.

Releases

UMD runtime browser version available on Github in the /releases directory.

Installation

There are three primary ways of adding SML to a project:

  1. Import it as a CDN package on the page
  2. Download the JavaScript file and host them yourself
  3. Install it using npm

Release Notes

Latest version: npm

Detailed release notes for each version are available on GitHub.

CDN

For using SML as runtime build in your browser you can use the latest version with:

<script src="https://unpkg.com/@gelight/sml-client"></script>

or

<script src="https://cdn.jsdelivr.net/npm/@gelight/sml-client"></script>

Download and Self Host

If you want to avoid using build tools but can't use a CDN in production then you can download the relevant .js file and host it using your own web server. You can then include it using a <script> tag, just like with the CDN approach.

The files can be browsed and downloaded from a CDN such as unpkg or jsDelivr.

NPM

NPM is the recommended installation method.

npm install @gelight/sml-client
yarn add @gelight/sml-client

Examples

Parse a simple SML document your node project

Parse your first simple SML Dokument

import { SmlDocument } from "@gelight/sml";

const doc = SmlDocument.parse(`
Hello
  About
    Name My name is SML
    Description I am a Simple Markup Language
  End
  About This is "a simple" SML document
End
`);

// Get all attributes from SML document
const attrs = doc.getRoot().getElement("About").getAttributes();

console.log(values);

A complete browser example by using per CDN import

The complete example is also available as on codepen.io

  1. Create a index.html file on your local computer
  2. Copy the sources below in your created html file and open it in your browser.
<html>
    <head>
        <title>SML - Simple Markup Language</title>
        <style>
            html, body {
                width: 100%;
                height: 100%;
              }
              body {
                background: linear-gradient(161deg, #333a47 0%, #1c1d24 100%);
                color: #8ca0c5;
                display: flex;
                justify-content: center;
                align-items: center;
              }
              .output {
                padding: 1rem;
                background: #3b4d6e;
                background: linear-gradient(161deg, #333a47 0%, #1c1d24 100%);
                box-shadow: 0 0 1rem 0 rgba(0,0,0,.5);
                border: 1px dashed #8ca0c5;
                border-radius: .5rem;
                margin: auto;
                display: flex;
                flex-direction: column;
              }
              
              .attribute {
                display: flex;
                
              }
              
              .value {
                border: .2rem solid #90ef8d;
                background: #5f9467;
                color: #fff;
                margin: .2rem;
                padding: .5rem;
                border-radius: .5rem;
              }
        </style>
    </head>
    <body>
        <div class="output"></div>

        <script src="https://unpkg.com/@gelight/sml-client"></script>
        <script>
          const renderAttributes = (attrs) => {
            let v = document.querySelector(".output");
            for (const attr of attrs) {
              let attrElm = document.createElement("div");
              attrElm.className = "attribute";

              for (const value of attr.getValues()) {
                let valueElm = document.createElement("div");
                valueElm.className = "value";
                let valueText = document.createTextNode(value);
                valueElm.appendChild(valueText);
                attrElm.appendChild(valueElm);
              }

              v.append(attrElm);
            }
          }

          const doc = SML.SmlDocument.parse(`
          Hello
            About
              Name My name is SML
              Description I am a Simple Markup Language
            End
            About This is "a simple" SML document
          End
          `);

          // Get all attributes from SML document
          const attrs = doc.getRoot().getElement("About").getAttributes();

          console.log(attrs);

          // Show attrubutes from element "About" as HTML
          renderAttributes(attrs);
        </script>
    </body>
</html>

Client to server requests with SmlRequest

This client example use the new SmlRequest class which is in experimental state.

<script src="https://unpkg.com/@gelight/sml-client"></script>
<script>
  const doc = await SML.SmlRequest.post("/peoples", SML.SmlDocument.parse(`
  MyBodyData
    FirstName William
    LastName Smith
    Age 37
  End
  `));

  /**
   * SmlRequest use the fatech api for requests and 
   * only expects a SmlDocument as a text/plain response from the server.
   * 
   * The SmlRequest class will parse the response for you and returns the 
   * response as an SmlDocument.
   * 
   * Available methods are GET, POST, PUT, PATCH and DELETE
   */
  const attrs = doc.getRoot().getAttributes();
</script>