Skip to content

Commit

Permalink
Add unaccentize & toContentSlug
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Oct 4, 2022
1 parent 5f791ed commit bbd1da8
Show file tree
Hide file tree
Showing 14 changed files with 4,337 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"@20minutes",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"no-console": [
"error",
{
"allow": ["warn", "error", "info"]
}
],
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
"@typescript-eslint/no-non-null-assertion": "off"
},
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
},
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
36 changes: 36 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 8 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
33 changes: 33 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
39 changes: 39 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CI: true
TZ: 'Europe/Paris'
NODE_ENV: 'test'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- name: checkout
uses: actions/checkout@v3

- name: use node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: install
run: yarn install

- name: lint
run: yarn lint

- name: test
run: yarn test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage
node_modules
lib
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src
tests
.eslintrc
jestconfig.json
tsconfig.json
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @20minutes/content-slug

[![Build status](https://github.com/20minutes/content-slug/actions/workflows/tests.yml/badge.svg)](https://github.com/20minutes/content-slug/actions/workflows/tests.yml)
[![NPM](https://img.shields.io/npm/v/@20minutes/content-slug)](https://www.npmjs.com/package/@20minutes/content-slug)

URL slugification used by 20 Minutes for content URL.

## Installation

```bash
npm install @20minutes/content-slug
```

## Usage

```javascript
import { toContentSlug, unaccentize} from '@20minutes/content-slug'

toContentSlug('j'ai mangé des pommes et des poires et c'était bon !')
// mange-pommes-poires-bon

unaccentize('mangé')
// mange
```

## License

[The MIT License](./LICENSE)
17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Config } from '@jest/types'

// Sync object
const config: Config.InitialOptions = {
verbose: true,
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!tests/*'],
coverageDirectory: './coverage',
coverageReporters: ['html', 'text-summary'],
// because TS generate some files in `.build` and jest might take them without that option
roots: ['<rootDir>/src/', '<rootDir>/tests/'],
}
export default config
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@20minutes/content-slug",
"version": "1.0.0",
"description": "Content slugification for 20 Minutes",
"license": "MIT",
"repository": "20minutes/content-slug",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/**/*"
],
"scripts": {
"build": "tsc",
"prepare" : "yarn build",
"test": "jest --silent false",
"lint": "eslint src/* tests/* *.ts"
},
"devDependencies": {
"@20minutes/eslint-config": "^1.2.4",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@types/jest": "^29.1.1",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"eslint": "^8.24.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-babel": "^5.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.3.0",
"jest": "^29.1.2",
"prettier": "^2.4.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
},
"dependencies": {
"url-slug": "^3.0.4"
}
}
Loading

0 comments on commit bbd1da8

Please sign in to comment.