Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
node-version: 17
cache: 'yarn'
- run: yarn
- run: yarn run build
- run: yarn run lint
test:
runs-on: ubuntu-20.04
Expand All @@ -27,25 +28,12 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'yarn'
- run: yarn
- run: yarn run build
- run: yarn run test:coverage
- uses: codecov/codecov-action@v2.1.0
build:
runs-on: ubuntu-20.04
strategy:
matrix:
node: [ '14', '16', '17' ]
needs: [lint, test]
steps:
- uses: actions/checkout@v2.3.5
- name: Use Node.js
uses: actions/setup-node@v2.4.1
with:
node-version: ${{ matrix.node }}
- run: yarn --pure-lockfile
- run: yarn run build
deploy:
runs-on: ubuntu-20.04
needs: [build]
needs: [test]
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2.3.5
Expand Down
14 changes: 0 additions & 14 deletions packages/random-name/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,3 @@ randomName('superb') // => "superb-admiring-allen"
randomName('superb', '_') // => "superb_admiring_allen"
randomName('', '_') // => "admiring_allen"
```

As a React hook
```js
import React from 'react'
import { useRandomName } from '@scaleway/random-name'

const Component = () => {
const name = useRandomName()

return (
<span>{name}</span>
)
}
```
5 changes: 1 addition & 4 deletions packages/random-name/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
"url": "https://github.com/scaleway/scaleway-lib",
"directory": "packages/random-name"
},
"license": "MIT",
"peerDependencies": {
"react": ">=16.8"
}
"license": "MIT"
}

This file was deleted.

19 changes: 1 addition & 18 deletions packages/random-name/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { renderHook } from '@testing-library/react-hooks'
import randomName, { useRandomName } from '..'
import randomName from '..'

describe('randomName', () => {
it('should return a random name separated by a dash', () => {
Expand Down Expand Up @@ -28,20 +27,4 @@ describe('randomName', () => {
expect.arrayContaining([expect.stringMatching('boring-wozniak')]),
)
})

describe('useRandomName', () => {
beforeAll(() => {
jest.spyOn(global.Math, 'random').mockReturnValue(0.4155913669444804)
})

afterAll(() => {
jest.spyOn(global.Math, 'random').mockRestore()
})

it('useTranslation should not be defined without I18nProvider', () => {
const { result } = renderHook(() => useRandomName())
expect(result.current).toMatchSnapshot()
})
})

})
6 changes: 0 additions & 6 deletions packages/random-name/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useCallback } from 'react'

const ADJECTIVES = [
'admiring',
'adoring',
Expand Down Expand Up @@ -839,8 +837,4 @@ const randomName = (prefix = '', separator = '-'): string => {
return prefix.length > 0 ? `${prefix}${separator}${name}` : name
}

const useRandomName = (prefix = '', separator = '-'): string =>
useCallback(() => randomName(prefix, separator), [prefix, separator])()

export { useRandomName }
export default randomName
10 changes: 10 additions & 0 deletions packages/use-random-name/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { join } = require('path');

module.exports = {
rules: {
'import/no-extraneous-dependencies': [
'error',
{ packageDir: [__dirname, join(__dirname, '../../')] }
]
}
};
4 changes: 4 additions & 0 deletions packages/use-random-name/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/__tests__/**
src
.eslintrc.cjs
!.npmignore
123 changes: 123 additions & 0 deletions packages/use-random-name/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

### 2.1.1 (2021-10-21)

**Note:** Version bump only for package @scaleway/random-name





## [2.1.0](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@2.0.0...@scaleway/random-name@2.1.0) (2021-07-21)


### Features

* **random-name:** base the generator on moby and expose react hook ([#281](https://github.com/scaleway/scaleway-lib/issues/281)) ([6e986be](https://github.com/scaleway/scaleway-lib/commit/6e986beb2609e533199a2b38b989c3b8b0c3c56b))



## 2.0.0 (2021-07-20)


### ⚠ BREAKING CHANGES

* migrate the codebase to typescript

### Code Refactoring

* migrate to typescript ([#272](https://github.com/scaleway/scaleway-lib/issues/272)) ([3923c68](https://github.com/scaleway/scaleway-lib/commit/3923c68d6f7feadee7e2e30e32c9ef5d1f3003b9))



### 1.3.2 (2021-05-11)

**Note:** Version bump only for package @scaleway/random-name





### 1.3.1 (2021-05-10)

**Note:** Version bump only for package @scaleway/random-name





# 1.3.0 (2021-03-04)


### Features

* updated eslint setting to force carriage return before return ([3514034](https://github.com/scaleway/scaleway-lib/commit/3514034804ae06083825adc3e57003ed8dba4933))





## 1.2.1 (2021-02-15)

**Note:** Version bump only for package @scaleway/random-name





# 1.2.0 (2021-01-28)


### Bug Fixes

* correct browser entrypoints ([2c0724d](https://github.com/scaleway/scaleway-lib/commit/2c0724d00b45664757c380188618908fcae2c606))
* **random-name:** add npmignore ([d7b7e70](https://github.com/scaleway/scaleway-lib/commit/d7b7e701db4ae090650408794a380ebe084e8407))


### Features

* migrate randomName from shire and scw-ui ([5729af8](https://github.com/scaleway/scaleway-lib/commit/5729af8c38a436679e948025dfff89c45a9b8e5c))





## [1.1.3](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@1.1.2...@scaleway/random-name@1.1.3) (2020-11-08)

**Note:** Version bump only for package @scaleway/random-name





## [1.1.2](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@1.1.1...@scaleway/random-name@1.1.2) (2020-10-28)


### Bug Fixes

* correct browser entrypoints ([8a7d0b5](https://github.com/scaleway/scaleway-lib/commit/8a7d0b503ee22eedb07d5021b3a3fd4e059e627a))





## [1.1.1](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@1.1.0...@scaleway/random-name@1.1.1) (2020-10-28)


### Bug Fixes

* **random-name:** add npmignore ([2731b54](https://github.com/scaleway/scaleway-lib/commit/2731b5452bb33fb369ee2370156e565b5a328d42))





# 1.1.0 (2020-10-28)


### Features

* migrate randomName from shire and scw-ui ([331a2f9](https://github.com/scaleway/scaleway-lib/commit/331a2f91a5aa777806bbc1dc1014fc5b6987db8c))
41 changes: 41 additions & 0 deletions packages/use-random-name/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# `@scaleway/random-name`

A tiny utility to generate random names

Fully inspired by [Moby name generator](https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go)

---

## Install

```bash
$ yarn add @scaleway/use-random-name
```

## Usage

As a React hook
```js
import React from 'react'
import useRandomName from '@scaleway/random-name'

const Component = () => {
const name = useRandomName()

return (
<span>{name}</span>
)
}
```

You can also access the underlying @scaleway/random-name package with a named export
```js
import { randomName } from '@scaleway/use-random-name'

// randomName(prefix: string = '', separator: string = '-'): string

randomName() // => "admiring-allen"
randomName('superb') // => "superb-admiring-allen"
randomName('superb', '_') // => "superb_admiring_allen"
randomName('', '_') // => "admiring_allen"
```
27 changes: 27 additions & 0 deletions packages/use-random-name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@scaleway/use-random-name",
"version": "0.1.0",
"description": "A small react utility to generate a random name",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"browser": {
"dist/index.js": "./dist/index.browser.js"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/scaleway/scaleway-lib",
"directory": "packages/use-random-name"
},
"license": "MIT",
"peerDependencies": {
"react": ">=16.8"
},
"dependencies": {
"@scaleway/random-name": "^2.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`useRandomName useTranslation should not be defined without I18nProvider 1`] = `"gracious-hermann"`;
17 changes: 17 additions & 0 deletions packages/use-random-name/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { renderHook } from '@testing-library/react-hooks'
import useRandomName from '..'

describe('useRandomName', () => {
beforeAll(() => {
jest.spyOn(global.Math, 'random').mockReturnValue(0.4155913669444804)
})

afterAll(() => {
jest.spyOn(global.Math, 'random').mockRestore()
})

it('useTranslation should not be defined without I18nProvider', () => {
const { result } = renderHook(() => useRandomName())
expect(result.current).toMatchSnapshot()
})
})
8 changes: 8 additions & 0 deletions packages/use-random-name/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import randomName from '@scaleway/random-name'
import { useCallback } from 'react'

const useRandomName = (prefix = '', separator = '-'): string =>
useCallback(() => randomName(prefix, separator), [prefix, separator])()

export default useRandomName
export { randomName }