Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 18, 2021
1 parent 261be4d commit 12498c9
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 238 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Expand Up @@ -12,10 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
298 changes: 145 additions & 153 deletions index.d.ts
@@ -1,141 +1,187 @@
declare namespace slugify {
interface Options {
/**
@default '-'
export interface Options {
/**
@default '-'
@example
```
import slugify = require('@sindresorhus/slugify');
@example
```
import slugify from '@sindresorhus/slugify';
slugify('BAR and baz');
//=> 'bar-and-baz'
slugify('BAR and baz');
//=> 'bar-and-baz'
slugify('BAR and baz', {separator: '_'});
//=> 'bar_and_baz'
slugify('BAR and baz', {separator: '_'});
//=> 'bar_and_baz'
slugify('BAR and baz', {separator: ''});
//=> 'barandbaz'
```
*/
readonly separator?: string;
slugify('BAR and baz', {separator: ''});
//=> 'barandbaz'
```
*/
readonly separator?: string;

/**
Make the slug lowercase.
/**
Make the slug lowercase.
@default true
@default true
@example
```
import slugify = require('@sindresorhus/slugify');
@example
```
import slugify from '@sindresorhus/slugify';
slugify('Déjà Vu!');
//=> 'deja-vu'
slugify('Déjà Vu!');
//=> 'deja-vu'
slugify('Déjà Vu!', {lowercase: false});
//=> 'Deja-Vu'
```
*/
readonly lowercase?: boolean;
slugify('Déjà Vu!', {lowercase: false});
//=> 'Deja-Vu'
```
*/
readonly lowercase?: boolean;

/**
Convert camelcase to separate words. Internally it does `fooBar` → `foo bar`.
/**
Convert camelcase to separate words. Internally it does `fooBar` → `foo bar`.
@default true
@default true
@example
```
import slugify = require('@sindresorhus/slugify');
@example
```
import slugify from '@sindresorhus/slugify';
slugify('fooBar');
//=> 'foo-bar'
slugify('fooBar');
//=> 'foo-bar'
slugify('fooBar', {decamelize: false});
//=> 'foobar'
```
*/
readonly decamelize?: boolean;
slugify('fooBar', {decamelize: false});
//=> 'foobar'
```
*/
readonly decamelize?: boolean;

/**
Add your own custom replacements.
/**
Add your own custom replacements.
The replacements are run on the original string before any other transformations.
The replacements are run on the original string before any other transformations.
This only overrides a default replacement if you set an item with the same key, like `&`.
This only overrides a default replacement if you set an item with the same key, like `&`.
Add a leading and trailing space to the replacement to have it separated by dashes.
Add a leading and trailing space to the replacement to have it separated by dashes.
@default [ ['&', ' and '], ['🦄', ' unicorn '], ['♥', ' love '] ]
@default [ ['&', ' and '], ['🦄', ' unicorn '], ['♥', ' love '] ]
@example
```
import slugify = require('@sindresorhus/slugify');
@example
```
import slugify from '@sindresorhus/slugify';
slugify('Foo@unicorn', {
customReplacements: [
['@', 'at']
]
});
//=> 'fooatunicorn'
slugify('foo@unicorn', {
customReplacements: [
['@', ' at ']
]
});
//=> 'foo-at-unicorn'
slugify('I love 🐶', {
customReplacements: [
['🐶', 'dogs']
]
});
//=> 'i-love-dogs'
```
*/
readonly customReplacements?: ReadonlyArray<[string, string]>;

/**
If your string starts with an underscore, it will be preserved in the slugified string.
Sometimes leading underscores are intentional, for example, filenames representing hidden paths on a website.
@default false
@example
```
import slugify from '@sindresorhus/slugify';
slugify('Foo@unicorn', {
customReplacements: [
['@', 'at']
]
});
//=> 'fooatunicorn'
slugify('_foo_bar');
//=> 'foo-bar'
slugify('foo@unicorn', {
customReplacements: [
['@', ' at ']
]
});
//=> 'foo-at-unicorn'
slugify('_foo_bar', {preserveLeadingUnderscore: true});
//=> '_foo-bar'
```
*/
readonly preserveLeadingUnderscore?: boolean;
}

slugify('I love 🐶', {
customReplacements: [
['🐶', 'dogs']
]
});
//=> 'i-love-dogs'
```
*/
readonly customReplacements?: ReadonlyArray<[string, string]>;
/**
Slugify a string.
/**
If your string starts with an underscore, it will be preserved in the slugified string.
@param string - String to slugify.
Sometimes leading underscores are intentional, for example, filenames representing hidden paths on a website.
@example
```
import slugify from '@sindresorhus/slugify';
@default false
slugify('I ♥ Dogs');
//=> 'i-love-dogs'
@example
```
import slugify = require('@sindresorhus/slugify');
slugify(' Déjà Vu! ');
//=> 'deja-vu'
slugify('_foo_bar');
//=> 'foo-bar'
slugify('fooBar 123 $#%');
//=> 'foo-bar-123'
slugify('_foo_bar', {preserveLeadingUnderscore: true});
//=> '_foo-bar'
```
*/
readonly preserveLeadingUnderscore?: boolean;
}
}
slugify('я люблю единорогов');
//=> 'ya-lyublyu-edinorogov'
```
*/
export default function slugify(string: string, options?: Options): string;

export interface CountableSlugify {
/**
Reset the counter.
@example
```
import {slugifyWithCounter} from '@sindresorhus/slugify';
const slugify = slugifyWithCounter();
slugify('foo bar');
//=> 'foo-bar'
slugify('foo bar');
//=> 'foo-bar-2'
slugify.reset();
slugify('foo bar');
//=> 'foo-bar'
```
*/
reset: () => void;

declare const slugify: {
/**
Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurences of the same string.
@param string - String to slugify.
@example
```
import slugify = require('@sindresorhus/slugify');
import {slugifyWithCounter} from '@sindresorhus/slugify';
const slugify = slugifyWithCounter();
const countableSlugify = slugify.counter();
countableSlugify('foo bar');
slugify('foo bar');
//=> 'foo-bar'
countableSlugify('foo bar');
slugify('foo bar');
//=> 'foo-bar-2'
countableSlugify.reset();
slugify.reset();
countableSlugify('foo bar');
slugify('foo bar');
//=> 'foo-bar'
```
Expand All @@ -153,63 +199,9 @@ declare const slugify: {
### Example
```
You can then use `slugify.counter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline.
*/
counter: () => {
/**
Reset the counter.
@example
```
import slugify = require('@sindresorhus/slugify');
const countableSlugify = slugify.counter();
countableSlugify('foo bar');
//=> 'foo-bar'
countableSlugify('foo bar');
//=> 'foo-bar-2'
countableSlugify.reset();
countableSlugify('foo bar');
//=> 'foo-bar'
```
*/
reset: () => void;

(
string: string,
options?: slugify.Options
): string;
};

/**
Slugify a string.
@param string - String to slugify.
@example
```
import slugify = require('@sindresorhus/slugify');
slugify('I ♥ Dogs');
//=> 'i-love-dogs'
slugify(' Déjà Vu! ');
//=> 'deja-vu'
slugify('fooBar 123 $#%');
//=> 'foo-bar-123'
slugify('я люблю единорогов');
//=> 'ya-lyublyu-edinorogov'
```
You can then use `slugifyWithCounter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline.
*/
(
string: string,
options?: slugify.Options
): string;
};
(string: string, options?: Options): string;
}

export = slugify;
export function slugifyWithCounter(): CountableSlugify;

0 comments on commit 12498c9

Please sign in to comment.