package/package.json000644 0000002776 3560116604 011562 0ustar00000000 000000 { "name": "react-display-name", "version": "0.2.5", "description": "utility to return a react components display name", "main": "./lib/getDisplayName.js", "typings": "./lib/getDisplayName.d.ts", "files": [ "lib", "!lib/spec" ], "scripts": { "build:lib": "mkdirp lib && babel src -d lib && cpy src/*.d.ts lib", "build:spec": "mkdirp lib/spec && babel spec -d lib/spec", "build": "npm run clean && npm run lint && npm run build:lib && npm run build:spec", "clean": "rimraf lib", "lint": "eslint src", "prepublish": "npm run build", "test": "npm run build:spec && mocha 'lib/spec/*Spec.js'" }, "repository": { "type": "git", "url": "git+https://github.com/jurassix/react-display-name.git" }, "keywords": [ "react", "redux", "getDisplayName" ], "author": "jurassix (clinton.ayres@gmail.com)", "license": "MIT", "bugs": { "url": "https://github.com/jurassix/react-display-name/issues" }, "homepage": "https://github.com/jurassix/react-display-name#readme", "devDependencies": { "@types/react": "*", "ajv": "^6.10.2", "babel-cli": "^6.26.0", "babel-eslint": "^10.0.3", "babel-preset-env": "^1.7.0", "babel-preset-react": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "chai": "^4.2.0", "cpy-cli": "^2.0.0", "eslint": "6.7.2", "eslint-plugin-import": "^2.18.2", "eslint-plugin-react": "7.17.0", "mkdirp": "^0.5.1", "mocha": "^6.2.2", "react": "^16.12.0", "rimraf": "^3.0.0" } } package/LICENSE000644 0000002100 3560116604 010256 0ustar00000000 000000 MIT License Copyright (c) 2015-2019 react-display-name authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/README.md000644 0000001635 3560116604 010544 0ustar00000000 000000 ```javascript npm install --save react-display-name ``` Get the displayName from a Component. This is a common pattern with React Higher Order Components (HoCs). This is a simple reusable utility to get the name of a component. Usage: ```javascript import {expect} from 'chai'; import React, {Component} from 'react'; import getDisplayName from 'react-display-name'; const container = (WrappedComponent) => { class Container extends Component { static displayName = `Container(${getDisplayName(WrappedComponent)})`; render() { return ( ); } } return Container; } class HelloWorld extends Component { render() { return (
Hello
); } } const HelloWorldPrime = container(HelloWorld); expect(getDisplayName(HelloWorldPrime)).to.equal('Container(HelloWorld)'); expect(HelloWorldPrime.displayName).to.equal('Container(HelloWorld)'); ``` package/lib/getDisplayName.d.ts000644 0000000261 3560116604 013525 0ustar00000000 000000 declare module 'react-display-name' { import * as React from 'react'; export default function getDisplayName( Component: React.ComponentType | string ): string; }package/lib/getDisplayName.js000644 0000000435 3560116604 013274 0ustar00000000 000000 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getDisplayName; function getDisplayName(Component) { return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown'); }