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

@calumk/codecup

v1.9.2

Published

A micro code-editor for awesome web pages

Downloads

685

Readme

Why?

CodeFlask was a brilliant project, but seems to be unmaintained, and it required some significant updates to work with a new project I am working on.

Kitchen Sink Example

cup = new codecup('#cf_holder', { 
    language: "javascript",
    lineNumbers: true ,
    copyButton: true,
    maxLines : 15,
    minLines : 5
});

Changes

  • Added max line number option
  • Switched from rollup to webpack
  • Added example folder
  • disabled e2e tests
  • Small theme tweaks (Border, rounded corners.)
  • updateded all codeflask references to codecup - 13/11/2023

[!IMPORTANT] Languages are now loaded async (via prismjs), so you can load any language you want, without having to bundle them all. - Jan 2024

[!NOTE] Languages supported are : https://prismjs.com/#supported-languages

Core Changes as PR

(Submitted as PR to CodeFlask, incase it gets picked up again)

  • Added support to destroy
  • Added Linenumber add / remove
  • Added Linenumber toggle
  • Added Readonly toggle

Installation

You can install codecup via npm:

npm i @calumk/codecup

Or use it directly in browser via cdn service:

https://cdn.jsdelivr.net/npm/@calumk/codecup

Usage

import codecup from '@calumk/codecup';

const cup = new codecup('#my-selector', { language: 'js' });

You can also pass a DOM element instead of a selector:

import codecup from 'codecup';

const editorElem = document.getElementById('editor');
const cup = new codecup(editorElem, { language: 'js' });

Usage with Shadow DOM:

import codecup from 'codecup';
...
const shadowElem = this.shadowRoot.querySelector('#editor');
const cup = new codecup(shadowElem, { language: 'js', styleParent: this.shadowRoot });

Listening for changes in editor

cup.onUpdate((code) => {
  // do something with code here.
  // this will trigger whenever the code
  // in the editor changes.
});

Updating the editor programatically

// This will also trigger .onUpdate()
cup.updateCode('const my_new_code_here = "Blabla"');

Getting the current code from editor

const code = cup.getCode();

Copy Button

The copy button is now enabled by default, and will copy the code to the clipboard when clicked.

it can be disabled by passing copyButton: false in the options.

const cup = new codecup('#my-selector', {
  language: 'javascript',
  copyButton: false
});

Enabling line numbers

import codecup from 'codecup';

const cup = new codecup('#my-selector', {
  language: 'js',
  lineNumbers: true
});

You can also toggle line numbers after the editor is created:

cup.toggleLineNumbers();

Setting max and min lines

[!IMPORTANT] As of 1.90, You can also set the max line number, (Default is 100), And the min line number, (Default is 1)

[!NOTE] If you want it to be a fixed number of lines, set both to the same number.

import codecup from 'codecup';

const cup = new codecup('#my-selector', {
  language: 'js',
  lineNumbers: true,
  maxLines: 10,
  minLines: 10
});

Enabling read only mode

import codecup from 'codecup';

const cup = new codecup('#my-selector', {
  language: 'javascript',
  readonly: true
});

changing other languages support:

cup.updateLanguage('ruby')
// 
cup.updateLanguage('javascript')
//

For Example to add change dynamically from 'Ruby' to 'javascript'

import Prism from 'prismjs';
import codecup from 'codecup';

const cup = new codecup('#my-selector', {
  language: 'ruby',
  readonly: true
});

cup.updateLanguage('javascript');