TOAST UI Code Snippet

2.3.3 · active · verified Sun Apr 19

TOAST UI Code Snippet (tui-code-snippet) is a comprehensive collection of modular, lightweight utility methods designed to simplify common JavaScript programming tasks. Currently stable at version 2.3.3, the library maintains a steady release cadence with regular updates including bug fixes and new features, such as the `ajax` module introduced in v2.3.0. A key differentiator since its 2.0 major release is its transition to a fully modular architecture, requiring developers to import individual functions or modules (e.g., `tui-code-snippet/array/inArray`) rather than a monolithic bundle. This approach minimizes bundle sizes by ensuring only the necessary utilities are included in an application. It provides functionalities across various domains including array manipulation, browser detection, collection processing, custom event management, DOM manipulation, class definition, date formatting, inheritance patterns, object utilities, and type checking. It explicitly supports both ES6 module syntax and CommonJS `require` patterns, making it versatile for modern JavaScript development environments. The library is a foundational component within the broader NHN TOAST UI ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and using several core utility functions like `inArray`, `isString`, `decodeHTMLEntity`, and `extend` for array, type, string, and object manipulation, respectively.

import inArray from 'tui-code-snippet/array/inArray';
import isString from 'tui-code-snippet/type/isString';
import decodeHTMLEntity from 'tui-code-snippet/string/decodeHTMLEntity';
import extend from 'tui-code-snippet/object/extend';

console.log('--- TOAST UI Code Snippet Quickstart ---');

// Example 1: Check if an item is in an array
const myArray = [1, 2, 3, 4, 5];
const searchTerm = 3;
console.log(`Is ${searchTerm} in [${myArray}]? ${inArray(searchTerm, myArray)}`);

const notFoundTerm = 6;
console.log(`Is ${notFoundTerm} in [${myArray}]? ${inArray(notFoundTerm, myArray)}`);

// Example 2: Check data type
const myString = "Hello, world!";
const myNumber = 123;
console.log(`"${myString}" is a string? ${isString(myString)}`);
console.log(`${myNumber} is a string? ${isString(myNumber)}`);

// Example 3: Decode HTML entities
const encodedHtml = "<div>Hello & World!</div>";
const decodedHtml = decodeHTMLEntity(encodedHtml);
console.log(`Decoded HTML: ${decodedHtml}`);

// Example 4: Extend an object
const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const extendedObj = extend({}, obj1, obj2);
console.log('Extended object:', extendedObj);

console.log('------------------------------------');

view raw JSON →