Skip to content

Commit

Permalink
feat: #36 - Rewrite code for Deno.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jan 23, 2021
1 parent 8a8788a commit 14cf61c
Show file tree
Hide file tree
Showing 22 changed files with 267 additions and 2,009 deletions.
7 changes: 3 additions & 4 deletions .dprintrc.json
Expand Up @@ -15,14 +15,13 @@
"excludes": [
"dist",
"coverage",
"temp",
".nyc_output",
"**/node_modules",
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.33.0.wasm",
"https://plugins.dprint.dev/json-0.7.2.wasm",
"https://plugins.dprint.dev/markdown-0.4.2.wasm"
"https://plugins.dprint.dev/typescript-0.38.4.wasm",
"https://plugins.dprint.dev/json-0.7.3.wasm",
"https://plugins.dprint.dev/markdown-0.5.1.wasm"
]
}
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,14 @@
name: CI
on: push
jobs:
test-library:
name: Deno test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: denolib/setup-deno@v2
with:
deno-version: v1.7
- name: Run tests
run: deno test
18 changes: 4 additions & 14 deletions .gitignore
@@ -1,14 +1,4 @@
/node_modules
/.nyc_output
*.js.map
/obj
/temp
/bin
*.suo
*.csproj
*.csproj.user
*.sln
/coverage
/.vs
/dist
/yarn-error.log
/node_modules
*.js.map
npm/dist
npm/LICENSE
4 changes: 0 additions & 4 deletions .mocharc.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .npmignore

This file was deleted.

5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
@@ -1,3 +1,3 @@
{
"typescript.tsdk": "./node_modules/typescript/lib"
"deno.enable": true
}
44 changes: 22 additions & 22 deletions LICENSE
@@ -1,22 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 David Sherret

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.

The MIT License (MIT)
Copyright (c) 2015-2021 David Sherret
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.
2 changes: 2 additions & 0 deletions build_npm.ps1
@@ -0,0 +1,2 @@
deno run -A --unstable scripts/build_npm.ts
cp LICENSE npm/LICENSE
File renamed without changes.
18 changes: 10 additions & 8 deletions src/tests/code-block-writer-tests.ts → mod.test.ts
@@ -1,5 +1,7 @@
import { expect } from "chai";
import CodeBlockWriter from "./../code-block-writer";
import CodeBlockWriter from "./mod.ts";
import { describe, expect, it } from "./test_helpers/mocha.ts";

Deno.test("dummy test", () => {});

describe("CodeBlockWriter", () => {
describe("default opts", () => {
Expand Down Expand Up @@ -902,7 +904,7 @@ describe("#setIndentationLevel", () => {

it("should not throw when providing an empty string", () => {
const writer = new CodeBlockWriter();
expect(() => writer.setIndentationLevel("")).to.not.throw();
expect(() => writer.setIndentationLevel("")).to.notThrow();
});

it("should throw when providing a string that doesn't contain only spaces and tabs", () => {
Expand Down Expand Up @@ -1050,7 +1052,7 @@ describe("#queueIndentationLevel", () => {

it("should not throw when providing an empty string", () => {
const writer = new CodeBlockWriter();
expect(() => writer.queueIndentationLevel("")).to.not.throw();
expect(() => writer.queueIndentationLevel("")).to.notThrow();
});

it("should throw when providing a string that doesn't contain only spaces and tabs", () => {
Expand Down Expand Up @@ -1250,7 +1252,7 @@ describe("#iterateLastChars", () => {
const returnValue = writer.iterateLastChars((char, index) => {
result.push([char, index]);
});
expect(result).to.deep.equal(expected);
expect(result).to.deepEqual(expected);
expect(returnValue).to.equal(undefined);
});

Expand Down Expand Up @@ -1631,15 +1633,15 @@ describe("useTabs", () => {
describe("#getOptions", () => {
it("should have the options that were passed in", () => {
const writer = new CodeBlockWriter({
useTabs: true,
indentNumberOfSpaces: 8,
newLine: "\r\n",
useTabs: true,
useSingleQuote: false,
});
expect(writer.getOptions()).to.deep.equal({
useTabs: true,
expect(writer.getOptions()).to.deepEqual({
indentNumberOfSpaces: 8,
newLine: "\r\n",
useTabs: true,
useSingleQuote: false,
});
});
Expand Down
13 changes: 8 additions & 5 deletions src/code-block-writer.ts → mod.ts
@@ -1,5 +1,5 @@
import { escapeForWithinString, getStringFromStrOrFunc } from "./utils/stringUtils";
import { CommentChar } from "./CommentChar";
import { CommentChar } from "./comment_char.ts";
import { escapeForWithinString, getStringFromStrOrFunc } from "./utils/string_utils.ts";

/**
* Options for the writer.
Expand Down Expand Up @@ -40,6 +40,8 @@ const CHARS = {
OPEN_BRACE: "{".charCodeAt(0),
CLOSE_BRACE: "}".charCodeAt(0),
DOLLAR_SIGN: "$".charCodeAt(0),
SPACE: " ".charCodeAt(0),
TAB: "\t".charCodeAt(0),
};
const isCharToHandle = new Set<number>([
CHARS.BACK_SLASH,
Expand Down Expand Up @@ -941,10 +943,11 @@ function getSpacesAndTabsCount(str: string) {
let spacesCount = 0;
let tabsCount = 0;

for (const char of str) {
if (char === " ")
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i);
if (charCode === CHARS.SPACE)
spacesCount++;
else if (char === "\t")
else if (charCode === CHARS.TAB)
tabsCount++;
}

Expand Down
22 changes: 22 additions & 0 deletions npm/package.json
@@ -0,0 +1,22 @@
{
"name": "code-block-writer",
"version": "10.1.1",
"description": "A simple code writer that assists with formatting and visualizing blocks of code.",
"main": "dist/code-block-writer.js",
"typings": "dist/code-block-writer.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/dsherret/code-block-writer.git"
},
"keywords": [
"typescript",
"writer",
"printer"
],
"author": "David Sherret",
"license": "MIT",
"bugs": {
"url": "https://github.com/dsherret/code-block-writer/issues"
},
"homepage": "https://github.com/dsherret/code-block-writer#readme"
}
56 changes: 0 additions & 56 deletions package.json

This file was deleted.

11 changes: 8 additions & 3 deletions readme.md
@@ -1,8 +1,7 @@
# code-block-writer

[![npm version](https://badge.fury.io/js/code-block-writer.svg)](https://badge.fury.io/js/code-block-writer)
[![Build Status](https://travis-ci.org/dsherret/code-block-writer.svg)](https://travis-ci.org/dsherret/code-block-writer)
[![Coverage Status](https://coveralls.io/repos/dsherret/code-block-writer/badge.svg?branch=master&service=github)](https://coveralls.io/github/dsherret/code-block-writer?branch=master)
[![CI](https://github.com/dsherret/code-block-writer/workflows/CI/badge.svg)](https://github.com/dsherret/code-block-writer/actions?query=workflow%3ACI)
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Code writer that assists with formatting and visualizing blocks of JavaScript or TypeScript code.
Expand All @@ -11,12 +10,18 @@ Code writer that assists with formatting and visualizing blocks of JavaScript or
npm install --save code-block-writer
```

Or with Deno:

```ts
import CodeBlockWriter from "https://deno.land/x/code_block_writer@x.x.x/mod.ts";
```

## Example

<!-- dprint-ignore -->

```typescript
import CodeBlockWriter from "code-block-writer";
import CodeBlockWriter from "https://deno.land/x/code_block_writer@x.x.x/mod.ts";

const writer = new CodeBlockWriter({
// optional options
Expand Down

0 comments on commit 14cf61c

Please sign in to comment.