diff options
Diffstat (limited to 'public/projects/react-small-apps/apps/todos/src/utilities')
| -rw-r--r-- | public/projects/react-small-apps/apps/todos/src/utilities/helpers.js | 20 | ||||
| -rw-r--r-- | public/projects/react-small-apps/apps/todos/src/utilities/hooks.js | 10 |
2 files changed, 30 insertions, 0 deletions
diff --git a/public/projects/react-small-apps/apps/todos/src/utilities/helpers.js b/public/projects/react-small-apps/apps/todos/src/utilities/helpers.js new file mode 100644 index 0000000..ab5ba41 --- /dev/null +++ b/public/projects/react-small-apps/apps/todos/src/utilities/helpers.js @@ -0,0 +1,20 @@ +/** + * Convert a text into a slug or id. + * https://gist.github.com/codeguy/6684588#gistcomment-3332719 + * + * @param {string} text Text to slugify. + */ +const slugify = (text) => { + return text + .toString() + .normalize("NFD") + .replace(/[\u0300-\u036f]/g, "") + .toLowerCase() + .trim() + .replace(/\s+/g, "-") + .replace(/[^\w-]+/g, "-") + .replace(/--+/g, "-") + .replace(/^-|-$/g, ""); +}; + +export { slugify }; diff --git a/public/projects/react-small-apps/apps/todos/src/utilities/hooks.js b/public/projects/react-small-apps/apps/todos/src/utilities/hooks.js new file mode 100644 index 0000000..0291324 --- /dev/null +++ b/public/projects/react-small-apps/apps/todos/src/utilities/hooks.js @@ -0,0 +1,10 @@ +import { useCallback, useState } from "react"; + +function useToggle(initialState = false) { + const [state, setState] = useState(initialState); + const toggle = useCallback(() => setState((state) => !state), []); + + return [state, toggle]; +} + +export default useToggle; |
