Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dpmland/deno-json-colorizer
A library for colorizing JSON strings for Deno
https://github.com/dpmland/deno-json-colorizer
deno deno-module javascript json library typescript
Last synced: about 1 month ago
JSON representation
A library for colorizing JSON strings for Deno
- Host: GitHub
- URL: https://github.com/dpmland/deno-json-colorizer
- Owner: dpmland
- License: gpl-3.0
- Created: 2022-06-29T18:02:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-02T19:01:18.000Z (over 2 years ago)
- Last Synced: 2024-10-28T12:16:50.371Z (about 2 months ago)
- Topics: deno, deno-module, javascript, json, library, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/json_colorize
- Size: 36.1 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deno - deno-json-colorizer - A library for colorizing JSON strings in Deno (Modules / String utils)
README
# deno-colorize-json
---
![](./docs/image.JPG)
A library for colorizing JSON strings for DENO
> _Adapted from the Node Version
> [json-colorizer](https://github.com/joeattardi/json-colorizer)_## Usage and Installation
### Installation
`dpm install json-colorize`
Or import like:
```ts
import { colorize } from 'https://deno.land/x/json_colorize/mod.ts';
```### Usage
```ts
import { colorize } from 'https://deno.land/x/json_colorize/mod.ts';
colorize('{ \'foo\': \'bar\' }');
```If you pass a string to the colorize function, it will treat it as
pre-serialized JSON. This can be used in order to colorize pretty-printed JSON:```ts
import { colorize } from 'https://deno.land/x/json_colorize/mod.ts';
const json = JSON.stringify({ 'foo': 'bar' }, null, 2);
colorize(json);
```And you can save the content in a variable and not print with this:
```ts
import { colorize } from 'https://deno.land/x/json_colorize/mod.ts';const msg = colorize('{ \'fooo\': \'baaar\' }', { print: false });
console.log(`Save in a variable ${msg}`);
```#### Customization colors
The tokens available are:
- `BRACE`
- `BRACKET`
- `COLON`
- `COMMA`
- `STRING_KEY`
- `STRING_LITERAL`
- `NUMBER_LITERAL`
- `BOOLEAN_LITERAL`
- `NULL_LITERAL`You can custom like:
```ts
import {
CODE_COLORS,
colorize,
} from 'https://deno.land/x/json_colorize/mod.ts';const example = {
aaaaaa: 'eeeee',
aaa: 2,
a: {
e: 'xd',
},
};colorize(JSON.stringify(example), {
colors: {
BRACE: CODE_COLORS.GRAY,
BRACKET: CODE_COLORS.GRAY,
COLON: CODE_COLORS.GRAY,
COMMA: CODE_COLORS.GRAY,
STRING_KEY: CODE_COLORS.BLUE,
STRING_LITERAL: CODE_COLORS.GREEN,
NUMBER_LITERAL: CODE_COLORS.YELLOW,
BOOLEAN_LITERAL: CODE_COLORS.BLUE,
NULL_LITERAL: CODE_COLORS.RED,
},
});
```## Information
- **Author:** Teo
- **Version:** 0.1.0
- **License:** GNU General Public License v3.0---
Made by [dpm](https://github.com/dpmland/dpm)