Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

c5-code-editor

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

c5-code-editor

This is a small utility that allows displaying source code nicely in a react app.

latest
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

c5-code-editor

This is a small utility that allows displaying source code nicely in a react app.

To install:

  npm install c5-code-editor

Sample usage:

import React, { useState } from 'react';
import Editor, { findColor } from 'c5-code-editor';

const App = () => {
  const [code, setCode] = useState(`import React from 'react'
  const App = (a) => {
    return (
      <div className="main-div">
        <h2>Hello world</h2>
      </div>
    )
  }`);

  return <Editor code={code} />;
};

Props:

Prop Nameoptionaltypedescription
code[required]stringthe code you want displayed
showLineNumbers[✔]booleanshow line numbers or not. Defaults to true.
codeElem[✔]stringcolor for the code elements
enableCodeElem[✔]booleancolor code elements or not. Defaults to true.
codeStr[✔]stringcolor of strings inside double quotes
enableCodeStr[✔]booleancolor code string or not. Defaults to true.
codeQuote[✔]stringcolor of quotation marks
enableCodeQuote[✔]booleancolor quotation marks or not. Defaults to true.
reserved[✔]stringcolor of reserved words
enableReserved[✔]booleancolor reserved words or not. Defaults to true.
appColor[✔]stringcolor of app like words
enableAppColor[✔]booleancolor app like words or not. Defaults to true.
defaultColor[✔]stringcolor of default like words
enableDefaultColor[✔]booleancolor default like words or not
codeSingle[✔]stringcolor of single quotes
enableCodeSingle[✔]booleancolor single quotes or not. Defaults to true.
betweenSingleQuotes[✔]stringcolor of contents between single quotes
enableBetweenSingleQuotes[✔]booleancolor contents between single quotes or not. Defaults to true.
parens[✔]stringcolor of parenthesis
enableParens[✔]booleancolor parenthesis or not. Defaults to true.
insideParens[✔]stringcolor of contents inside of parenthesis
enableInsideParens[✔]booleancolor contents inside of parenthesis or not. Defaults to true.
alternates[✔]stringcolor of alternate words
enableAlternates[✔]booleancolor alternate words or not. Defaults to true.
customReserveWords[✔]array of stringsan array of words that you would like to include in the coloring of reserve words. defaults to empty array
customAppWords[✔]array of stringsan array of words that you would like to include in the coloring of app words. defaults to empty array
customDefaults[✔]array of stringsan array of words that you would like to include in the coloring of default words. defaults to empty array
customAlternatives[✔]array of stringsan array of words that you would like to include in the coloring of alternative words. defaults to empty array
parserType[✔]stringtype of parser to use with Prettier to format the code string. Defaults to 'babel'
format[✔]booleanformat code or not. defaults to true

words list:

export const reservedWords: string[] = [
  'id',
  'className',
  'class',
  'if',
  'then',
  'json',
  'application',
  'method',
  'async',
  'await',
  'for',
];

export const defaultWords: string[] = [
  'return',
  'import',
  'console',
  'log',
  'from',
];

export const appWords: string[] = [
  'React',
  'Axios',
  'const',
  'function',
  'let',
  'var',
  'avion',
];

export const alternateWords: string[] = ['url', 'params', 'data', 'cors'];

Parser Types:

export type Parsers =
  | 'babel'
  | 'css'
  | 'json'
  | 'flow'
  | 'babel-flow'
  | 'babel-ts'
  | 'typescript'
  | 'json'
  | 'markdown'
  | 'html';

FAQs

Package last updated on 20 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts