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
File renamed without changes.
8 changes: 0 additions & 8 deletions badge-maker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ badge build passed :brightgreen > mybadge.svg

### As a library

With CommonJS in JavaScript,

```js
const { makeBadge, ValidationError } = require('badge-maker')
```

With ESM or TypeScript,

```ts
import { makeBadge, ValidationError } from 'badge-maker'
```
Expand Down
6 changes: 2 additions & 4 deletions badge-maker/lib/badge-cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env node

'use strict'

const { namedColors } = require('./color')
const { makeBadge } = require('./index')
import { namedColors } from './color.js'
import { makeBadge } from './index.js'

if (process.argv.length < 4) {
console.log('Usage: badge label message [:color] [@style]')
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions badge-maker/lib/badge-renderers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const anafanafo = require('anafanafo')
const { brightness } = require('./color')
const { XmlElement, ElementList } = require('./xml')
import anafanafo from 'anafanafo'
import { brightness } from './color.js'
import { XmlElement, ElementList } from './xml.js'

// https://github.com/badges/shields/pull/1132
const FONT_SCALE_UP_FACTOR = 10
Expand Down Expand Up @@ -984,7 +984,7 @@ function forTheBadge({
)
}

module.exports = {
export default {
plastic: params => Plastic.render(params),
flat: params => Flat.render(params),
'flat-square': params => FlatSquare.render(params),
Expand Down
20 changes: 6 additions & 14 deletions badge-maker/lib/color.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { fromString } = require('css-color-converter')
import { fromString } from 'css-color-converter'

// When updating these, be sure also to update the list in `badge-maker/README.md`.
const namedColors = {
export const namedColors = {
brightgreen: '#4c1',
green: '#97ca00',
yellow: '#dfb317',
Expand Down Expand Up @@ -33,15 +33,15 @@ Object.entries(aliases).forEach(([alias, original]) => {
// This function returns false for `#ccc`. However `isCSSColor('#ccc')` is
// true.
const hexColorRegex = /^([\da-f]{3}){1,2}$/i
function isHexColor(s = '') {
export function isHexColor(s = '') {
return hexColorRegex.test(s)
}

function isCSSColor(color) {
return typeof color === 'string' && fromString(color.trim())
}

function normalizeColor(color) {
export function normalizeColor(color) {
if (color === undefined) {
return undefined
} else if (color in namedColors) {
Expand All @@ -57,7 +57,7 @@ function normalizeColor(color) {
}
}

function toSvgColor(color) {
export function toSvgColor(color) {
const normalized = normalizeColor(color)
if (normalized in namedColors) {
return namedColors[normalized]
Expand All @@ -68,7 +68,7 @@ function toSvgColor(color) {
}
}

function brightness(color) {
export function brightness(color) {
if (color) {
const cssColor = fromString(color)
if (cssColor) {
Expand All @@ -78,11 +78,3 @@ function brightness(color) {
}
return 0
}

module.exports = {
namedColors,
isHexColor,
normalizeColor,
toSvgColor,
brightness,
}
9 changes: 2 additions & 7 deletions badge-maker/lib/color.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict'

const { test, given, forCases } = require('sazerac')
const {
isHexColor,
normalizeColor,
toSvgColor,
brightness,
} = require('./color')
import { test, given, forCases } from 'sazerac'
import { isHexColor, normalizeColor, toSvgColor, brightness } from './color.js'

test(isHexColor, () => {
forCases([given('f00bae'), given('4c1'), given('ABC123')]).expect(true)
Expand Down
6 changes: 1 addition & 5 deletions badge-maker/lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
const DEFAULT_LOGO_HEIGHT = 14

module.exports = {
DEFAULT_LOGO_HEIGHT,
}
export const DEFAULT_LOGO_HEIGHT = 14
11 changes: 3 additions & 8 deletions badge-maker/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* @module badge-maker
*/

const _makeBadge = require('./make-badge')
import _makeBadge from './make-badge.js'

class ValidationError extends Error {}
export class ValidationError extends Error {}

function _validate(format) {
if (format !== Object(format)) {
Expand Down Expand Up @@ -105,13 +105,8 @@ function _clean(format) {
* @returns {string} Badge in SVG format
* @see https://github.com/badges/shields/tree/master/badge-maker/README.md
*/
function makeBadge(format) {
export function makeBadge(format) {
_validate(format)
const cleanedFormat = _clean(format)
return _makeBadge(cleanedFormat)
}

module.exports = {
makeBadge,
ValidationError,
}
File renamed without changes.
12 changes: 5 additions & 7 deletions badge-maker/lib/make-badge.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict'

const { normalizeColor, toSvgColor } = require('./color')
const badgeRenderers = require('./badge-renderers')
const { stripXmlWhitespace } = require('./xml')
const { DEFAULT_LOGO_HEIGHT } = require('./constants')
import { normalizeColor, toSvgColor } from './color.js'
import badgeRenderers from './badge-renderers.js'
import { stripXmlWhitespace } from './xml.js'
import { DEFAULT_LOGO_HEIGHT } from './constants.js'

/*
note: makeBadge() is fairly thinly wrapped so if we are making changes here
it is likely this will impact on the package's public interface in index.js
*/
module.exports = function makeBadge({
export default function makeBadge({
format,
style = 'flat',
label,
Expand Down
File renamed without changes.
12 changes: 4 additions & 8 deletions badge-maker/lib/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
* @module
*/

'use strict'

function stripXmlWhitespace(xml) {
export function stripXmlWhitespace(xml) {
return xml.replace(/>\s+/g, '>').replace(/<\s+/g, '<').trim()
}

function escapeXml(s) {
export function escapeXml(s) {
if (typeof s === 'number') {
return s
} else if (s === undefined || typeof s !== 'string') {
Expand All @@ -26,7 +24,7 @@ function escapeXml(s) {
/**
* Representation of an XML element
*/
class XmlElement {
export class XmlElement {
/**
* Xml Element Constructor
*
Expand Down Expand Up @@ -77,7 +75,7 @@ class XmlElement {
* Convenience class. Sometimes it is useful to return an object that behaves
* like an XmlElement but renders multiple XML tags (not wrapped in a <g>).
*/
class ElementList {
export class ElementList {
constructor({ content = [] }) {
this.content = content
}
Expand All @@ -92,5 +90,3 @@ class ElementList {
)
}
}

module.exports = { escapeXml, stripXmlWhitespace, XmlElement, ElementList }
6 changes: 2 additions & 4 deletions badge-maker/lib/xml.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const { test, given } = require('sazerac')
const { XmlElement } = require('./xml')
import { test, given } from 'sazerac'
import { XmlElement } from './xml.js'

function testRender(params) {
return new XmlElement(params).render()
Expand Down
3 changes: 2 additions & 1 deletion badge-maker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "badge-maker",
"version": "4.1.0",
"type": "module",
"exports": "./lib/index.js",
"description": "Shields.io badge library",
"keywords": [
"GitHub",
Expand All @@ -10,7 +12,6 @@
"shields.io"
],
"types": "index.d.ts",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/badges/shields.git",
Expand Down
Loading