Skip to content

Commit

Permalink
Deno first
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Jul 10, 2024
1 parent 6d305d2 commit 61f7f42
Show file tree
Hide file tree
Showing 22 changed files with 645 additions and 635 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: "1.8.3"

- name: Lint and formatting
run: biome ci .

- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: 1.x

- name: Run tests
run: deno test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist
node_modules
.vscode
package-lock.json
yarn.lock
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

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

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome", "denoland.vscode-deno"]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"deno.enable": true,
"editor.defaultFormatter": "biomejs.biome"
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 3.0.0

- `text-clipper` has become a Deno-first library and is now available on [Jsr.io](https://jsr.io).
Instructions for installation on Node.js/Bun are still included.

## 2.2.0

- Implement #14: Add `stripTags` option.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Arend van Beelen jr., Speakap B.V.
Copyright (c) 2016-2024 Arend van Beelen jr., Speakap B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

Fast and correct clip functions for HTML and plain text.

[![Build Status](https://travis-ci.org/arendjr/text-clipper.svg?branch=master)](https://travis-ci.org/arendjr/text-clipper)
[![text-clipper on NPM](https://img.shields.io/npm/v/text-clipper.svg)](https://www.npmjs.com/package/text-clipper)

## Why use text-clipper?

text-clipper offers the following advantages over similar libraries that allow clipping HTML:
Expand All @@ -22,43 +19,46 @@ text-clipper offers the following advantages over similar libraries that allow c

## Usage

### Node.js
### Deno

First install the `text-clipper` package:
First install the package:

```sh
$ yarn add text-clipper # or: npm install --save text-clipper
$ deno add @arendjr/text-clipper
```

If compatibility with Internet Explorer is required, make sure you have a polyfill for
`Array.prototype.includes()`.

Once installed, you can use it as follows:

```js
import clip from "text-clipper"; // or: const clip = require("text-clipper").default;
import clip from "@arendjr/text-clipper";

const clippedString = clip(string, 80); // returns a string of at most 80 characters

const clippedHtml = clip(htmlString, 140, { html: true, maxLines: 5 });
```

### Deno
### Bun

When using Deno, you can import right away:
Install using the following command instead:

```js
import clip from "https://raw.githubusercontent.com/arendjr/text-clipper/master/mod.ts";
```sh
$ bunx jsr add @arendjr/text-clipper
```

And use it like this:
For usage instructions, see above.

```js
const clippedString = clip(string, 80); // returns a string of at most 80 characters
### Node.js

const clippedHtml = clip(htmlString, 140, { html: true, maxLines: 5 });
Install using one of the following commands, depending on your package manager:

```sh
$ npx jsr add @arendjr/text-clipper # If using NPM
$ yarn dlx jsr add @arendjr/text-clipper # If using Yarn
$ pnpm dlx jsr add @arendjr/text-clipper # If using PNPM
```

For usage instructions, see above.

## Options

### breakWords
Expand Down Expand Up @@ -107,3 +107,13 @@ clip(input, 140, { html: true, stripTags: ["img", "svg"] });
```

Tag names must be specified in lowercase.

## Changelog

See [CHANGELOG.md](CHANGELOG.md).

## License

Licensed under the MIT License.

See [LICENSE](LICENSE).
12 changes: 12 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@arendjr/text-clipper",
"version": "3.0.0",
"compilerOptions": {
"allowJs": true,
"strict": true
},
"lock": false,
"publish": {
"include": ["src"]
}
}
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion mod.ts

This file was deleted.

43 changes: 0 additions & 43 deletions package.json

This file was deleted.

8 changes: 0 additions & 8 deletions tests/unit/examples.spec.ts

This file was deleted.

10 changes: 10 additions & 0 deletions tests/unit/examples.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { assertEquals } from "jsr:@std/assert";

import clip from "../../src/index.ts";

Deno.test("examples: test examples from the README", () => {
assertEquals(clip("foo", 3), "foo");
assertEquals(clip("foo", 2), "f…");
assertEquals(clip("foo bar", 5), "foo …");
assertEquals(clip("foo\nbar", 5), "foo");
});
Loading

0 comments on commit 61f7f42

Please sign in to comment.