GithubHelp home page GithubHelp logo

cksachdev / super-expressive-playground Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nartc/super-expressive-playground

0.0 0.0 0.0 1.03 MB

SuperExpressive Playground

Home Page: https://sepg.netlify.app

JavaScript 6.21% TypeScript 73.01% CSS 17.10% HTML 3.68%

super-expressive-playground's Introduction

SuperExpressive Playground

This is the playground for SuperExpressive Library.

Table Of Content

Working application

Check out the working app -> https://sepg.netlify.app/

SuperExpressive Playground by @nartc

Features

  • Use the code editor to write Regular Expression using SuperExpressive API

  • Test the generated RegExp

  • Mobile friendly - @trungk18

  • Automatic execution

Technologies

Challenges

There are a couple of challenges that I ran into while working on this project.

Monaco Editor

Monaco is a powerful library, but it's also very complex. The way it's loaded is pretty tricky. However, the integration is quite smooth using ngx-monaco-editor. It was quite satisfied when I was able to load extra library type definitions (for SuperExpressive intellisense) into the Monaco instance

Executing the value of the editor

This is one tricky task as eval() is considered bad practice. So, I use new Function() instead. Also, I need to execute a snippet like:

SuperExpressive().anyChar.toRegex();

which will execute SuperExpressive() which is a 3rd-party API. Hence, in order for me to execute that, I need to assign SuperExpressive onto the window object.

import SuperExpressive from "super-expressive";

window.SuperExpressive = SuperExpressive;

Furthermore, I only want to execute a single-invoke of SuperExpressive() at a time, so I need to trim the editor's value.

Scully and Monaco

Scully will not work with Monaco as is because Scully will generate the html from the Angular build bundle and in turns will inject several <script> tags that were used to load Monaco. With multiple <script> tags with the same value (because Scully generates multiple html for multiple routes), Monaco complains that it's already been loaded.

To resolve that, I write a quick plugin to remove Monaco related <script> from the generated html by Scully.

function removeMonacoScriptPluginHandler(html: string) {
  return Promise.resolve(
    html
      .replace(/<script.+(?:editor\.main(?:\.nls)\.js)"><\/script>/g, "") // remove duplicate loader
      .replace(/<script.+(?:tsMode\.js|typescript\.js)"><\/script>/g, "") // remove duplicate loader
      .replace(/<ngx-monaco-editor.+><\/ngx-monaco-editor>/g, "") // remove flickering
  );
}

Mobile Responsiveness

Again, because of how Monaco is loaded and rendered, it's tricky to get Mobile Responsiveness right which I haven't paid too much attention to for the first iteration.

Contribution

Any contribution is welcome

Credit

License

The MIT License (MIT)

Copyright (c) 2015 Chris Kibble

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

super-expressive-playground's People

Contributors

nartc avatar trungvose avatar

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.