@namefully/react
Version:
namefully for React
214 lines (202 loc) • 7.42 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("React"), require("namefully"));
else if(typeof define === 'function' && define.amd)
define("namefully", ["React", "namefully"], factory);
else if(typeof exports === 'object')
exports["namefully"] = factory(require("React"), require("namefully"));
else
root["namefully"] = factory(root["React"], root["namefully"]);
})(window, function(__WEBPACK_EXTERNAL_MODULE__2__, __WEBPACK_EXTERNAL_MODULE__3__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __webpack_require__(2);
const namefully_1 = __webpack_require__(3);
/**
* Namefully, react-based component to handle person names.
* @function component or presentational react component
*
* @usageNotes
* ```tsx
* <Namefully
* raw={'Person Name'}
* options={{...SomeOptions}}
* method={"namefully's method"}
* args={['args', 'for', 'method' ...]}
* tag={'html tag'}
* position={'left or right of children'}
*
* className={'a-class'}
* style={{...yourStyles}}
* moreHtmlAttrs={}
* >
* <htmltag>content</htmltag>
* </Namefully>
* ```
*
* @example
* ```tsx
* import * as React from 'react';
* import * as ReactDOM from 'react-dom';
*
* import { Namefully } from '@namefully/react';
*
* const App = () => {
* return (
* <h1>
* Hello, <Namefully raw='John Smith'/>!
* </h1>
* )
* };
*
* ReactDOM.render(<App />, document.getElementById('example'));
* ```
* Happy name-handling!
*/
exports.default = (props) => {
const { raw, options, method, args, tag, position, children } = props, htmlAttrs = __rest(props, ["raw", "options", "method", "args", "tag", "position", "children"]);
const name = new namefully_1.Namefully(raw, options);
const content = executeInnerMethod(name, name[method || 'fullName'], args);
const Tag = tag || 'span';
if (position === 'left' || position === 'l') {
return (React.createElement(Tag, Object.assign({}, htmlAttrs),
children,
" ",
content));
}
return (React.createElement(Tag, Object.assign({}, htmlAttrs),
content,
" ",
children));
};
// tslint:disable-next-line
function executeInnerMethod(context, fn, args) {
const content = fn.apply(context, args);
return Array.isArray(content) ? content.join(' ') : content;
}
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Main entrypoint for Namefully
*/
__export(__webpack_require__(0));
var Namefully_1 = __webpack_require__(0);
exports.Namefully = Namefully_1.default;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE__2__;
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
/***/ })
/******/ ]);
});
//# sourceMappingURL=react.js.map