2

While importing a package to my code, for example:

import { Text, View, StyleSheet } from "react-native";

How I can know the complete list of utilities functions like Text, View etc available in package react-native ?

Is there any npm command for this. I couldn't find any such list/docs in https://www.npmjs.com/package/react-native too.

Om Sao
  • 7,064
  • 2
  • 47
  • 61
  • You can find `react-native`'s full list of it's components in it's official documentations [here](https://reactnative.dev/docs/components-and-apis).
    Sadly, I don't know if there are any npm commands to do this with.
    – Mineko Kayui Sep 06 '20 at 04:52
  • @MinekoKayui: Thank you for the reply. `react-native` here is just an example and for it documentation is available. What I am specifically looking is a npm command listing all exports possible from the package. Sadly it's not straight forward. – Om Sao Sep 09 '20 at 03:19
  • Ooh, I see, I dint quite understand the question clearly, sorry for the misunderstanding. – Mineko Kayui Sep 09 '20 at 03:28

2 Answers2

1

You can't exactly run an npm command, because npm is a package manager for node, commands run in npm will be for package management, whereas commands run in node itself is what you need to get the utilities functions.

I did a lot of research on this and found one solution. What you want to do is, after installing the package you want to check on using npm, let's say it's discord.js:

npm install discord.js

Now, run node directly, no index.js or any other files required.

node

Then, use the following command:

Object.keys(require('discord.js'))

While in node, this will return a list of all it's utilities. Of course, this example was using discord.js, though it can be any npm packages with utility functions.

This should return something like:

[
  'BaseClient',             'Client',                 'Shard',
  'ShardClientUtil',        'ShardingManager',        'WebhookClient',
  'ActivityFlags',          'BitField',               'Collection',
  'Constants',              'DataResolver',           'BaseManager',
  'DiscordAPIError',        'HTTPError',              'MessageFlags',
  'Intents',                'Permissions',            'Speaking',
  'Snowflake',              'SnowflakeUtil',          'Structures',
  'SystemChannelFlags',     'UserFlags',              'Util',
  'version',                'ChannelManager',         'GuildChannelManager',
  'GuildEmojiManager',      'GuildEmojiRoleManager',  'GuildMemberManager',
  'GuildMemberRoleManager', 'GuildManager',           'ReactionManager',
  'ReactionUserManager',    'MessageManager',         'PresenceManager',
  'RoleManager',            'UserManager',            'discordSort',
  'escapeMarkdown',         'fetchRecommendedShards', 'resolveColor',
  'resolveString',          'splitMessage',           'Base',
  'Activity',               'APIMessage',             'BaseGuildEmoji',
  'CategoryChannel',        'Channel',                'ClientApplication',
  'ClientUser',             'Collector',              'DMChannel',
  'Emoji',                  'Guild',                  'GuildAuditLogs',
  'GuildChannel',           'GuildEmoji',             'GuildMember',
  'GuildPreview',           'Integration',            'Invite',
  'Message',                'MessageAttachment',      'MessageCollector',
  'MessageEmbed',           'MessageMentions',        'MessageReaction',
  'NewsChannel',            'PermissionOverwrites',   'Presence',
  'ClientPresence',         'ReactionCollector',      'ReactionEmoji',
  'RichPresenceAssets',     'Role',                   'StoreChannel',
  'Team',                   'TeamMember',             'TextChannel',
  'User',                   'VoiceChannel',           'VoiceRegion',
  'VoiceState',             'Webhook',                'WebSocket'
]

Which is basically all the utility functions available in discord.js. Now, sometimes, you will run into this error:

SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import

This is because I'm running it from node and not from a module or app. Then if you try it inside a non-module package, like a bot in discord.js, it will return this error:

SyntaxError: Cannot use import statement outside a module

These two errors above won't show up if you're making a module instead and calling import from inside the module.


This is because a discord.js bot isn't a module and if I force define module in the package.json, it will break. In this case, there's nothing you can do from inside, you can try to look up it's documentations or source code to find it yourself.

Here're some references to using this command:

Mineko Kayui
  • 761
  • 4
  • 15
-1

You could do this

import Rn from "react-native";

console.log(Object.keys(Rn));
MRsabs
  • 85
  • 3